sqlite delete row count

南楼画角 提交于 2019-12-02 22:22:26

问题


I need to write a SQLlite query that will delete rows from a table above 200. I was thinking this would work:

DELETE FROM [tbl_names] WHERE count(*) > 200

but that gives me: misuse of aggregate function count()

I know there is a limit clause I can use, but if I use:

DELETE FROM [tbl_names] LIMIT 200

that looks like it will delete the first 200 rows.


回答1:


All rows in an SQLite have rowid field, which you can use to find rows greater than 200. For example:

DELETE FROM [tbl_names] WHERE rowid > 200

You could also use an offset with your limit:

DELETE FROM [tbl_names] LIMIT 10000 offset 200

using the roqid seems to be the better choice.



来源:https://stackoverflow.com/questions/7700376/sqlite-delete-row-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!