SQLite的条件插入或更换 [英] SQLite conditional insert or replace
本文介绍了SQLite的条件插入或更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图插入或更新一条记录SQLite数据库,如果新值大于旧的仅大更新值。
I'm trying to insert or update a record into a sqlite database, and only update the value if the new value is greater than the old.
模式是:
CREATE table IF NOT EXISTS SearchTable
(Owner INTEGER PRIMARY KEY, Generations INTEGER DEFAULT 0)
我已经试过这样的命令:
I've tried commands like this:
INSERT OR REPLACE INTO SearchTable(Owner, Generations)
VALUES (?, MAX((SELECT Generations FROM SearchTable WHERE Owner = ?), ?))
但它给了我为后代一个空值。
but it gives me a null value for the Generations.
我可以利用一些帮助。
推荐答案
尝试
INSERT OR REPLACE INTO SearchTable(Owner, Generations)
SELECT ?, MAX(Generations) FROM SearchTable WHERE Owner = ?
这篇关于SQLite的条件插入或更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文