我无法使用sqlite运行此查询
if 0<(select COUNT(*) from Repetition where (Word='behnam' and Topic='mine')) begin update Repetition set Counts=1+ (select Counts from Repetition where (Word='behnam' and Topic='mine')) end else begin insert Repetition(Word,Topic,Counts)values('behnam','mine',1) end
sqlite没有IF语句(
see the list of supported queries)
Insetad,查看ERIC B关于另一个thread的建议.你实际上是在做一个UPSERT(如果记录存在则更新,如果不存在则INSERT). Eric B.有一个很好的例子,说明如何在sqlite语法中使用sqlite中的“INSERT OR REPLACE”功能.基本上,你做的事情如下:
INSERT OR REPLACE INTO Repetition (Word,Counts) VALUES ( 'behnam',coalesce((select Counts + 1 from Repetition where Word = 'behnam',AND Topic = 'mine),1) )