我无法使用 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
它说“IF 附近的语法错误”
我该如何解决这个问题
SQLite 没有 IF 语句(查看支持的查询列表 http://www.sqlite.org/lang.html)
Insetad,看看ERIC B对另一个人的建议thread https://stackoverflow.com/questions/418898/sqlite-upsert-not-insert-or-replace。您实际上正在考虑执行 UPSERT(如果记录存在则更新,如果不存在则插入)。 Eric B. 有一个很好的示例,说明如何利用 SQLite 中的“INSERT OR REPLACE”功能在 SQLite 语法中执行此操作。基本上,你会做类似的事情:
INSERT OR REPLACE INTO Repetition (Word, Topic, Counts)
VALUES ( 'behnam', 'mine',
coalesce((select Counts + 1 from Repetition
where Word = 'behnam', AND Topic = 'mine)
,1)
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)