需要網sqlite數據庫中插入或替換記錄,並且更新條件是,新的值大於舊的值。
schema
:
CREATE table IF NOT EXISTS SearchTable
(Owner INTEGER PRIMARY KEY, Generations INTEGER DEFAULT 0)
試過下面的命令:
INSERT OR REPLACE INTO SearchTable(Owner, Generations)
VALUES (?, MAX((SELECT Generations FROM SearchTable WHERE Owner = ?), ?))
但是返回的結果是空值。
INSERT OR REPLACE INTO SearchTable(Owner, Generations) SELECT 5, MIN(3, COALESCE(Generations, 999)) FROM SearchTable WHERE Owner = 5
試試吧