我想从 Android 应用程序更新我的 SQLite 数据库中的前 n 条记录。以下是我迄今为止尝试过的查询。我在 order
附近遇到语法错误。
update label set label_is_used = 1 where label_name !='temp' and label_cnt != 0 order by label_cnt desc limit 3
------------------------------------
update label set label_is_used = 1 where label_name !='temp' and label_cnt != 0 order by label_cnt limit 3
来自docs ,这应该符合语法。
我哪里错了?
最佳答案
If SQLite is built with the SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option then the syntax of the UPDATE statement is extended with optional ORDER BY and LIMIT clauses
默认情况下不启用该选项,当然在 Android 上也不启用。
作为解决方法,确定要在子查询中更新的记录:
UPDATE label
SET label_is_used = 1
WHERE label_id IN (SELECT label_id -- or whatever you use as ID
FROM label
WHERE label_name != 'temp'
AND label_cnt != 0
ORDER BY label_cnt DESC
LIMIT 3);
关于android - 更新 SQLite 中的前 n 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35649983/