如何删除具有特定行号的数据(sqlite)

发布于 2024-08-07 08:21:24 字数 57 浏览 2 评论 0原文

我有一个表人员(姓名、地址、电话),我的表有 2000 多行。我想删除 1000 行。查询情况如何?

I have a table people (name, address, phone), my table have 2000+ rows. I want to delete 1000 rows. How's about the query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

临走之时 2024-08-14 08:21:24

我假设您想要删除“前 1000 行”,因为“select”查询结果的未排序顺序没有排序参数,也没有条件,在这种情况下您做错了。

但是,作为一项学术练习,您可以这样做。 SQLite 中的所有行都有 rowid 字段,您可以使用该字段来查找这 ​​1000 行的结束位置。

sqlite> create table t(s string);
sqlite> insert into t values('a1');
sqlite> insert into t values('a2');
sqlite> insert into t values('a3');
sqlite> insert into t values('a4');
sqlite> select * from t;
a1
a2
a3
a4
sqlite> delete from t where rowid < (select rowid from t limit 2,1);
sqlite> select * from t;
a3
a4

I assume you want to delete "first 1000 rows" given the unsorted order of the result of "select" query with no sorting arguments and no criteria, in which case you are doing something wrong.

But, as an academic exercise, here is how you'd do it. All rows in an SQLite have rowid field, which you can use to find where those 1000 rows end.

sqlite> create table t(s string);
sqlite> insert into t values('a1');
sqlite> insert into t values('a2');
sqlite> insert into t values('a3');
sqlite> insert into t values('a4');
sqlite> select * from t;
a1
a2
a3
a4
sqlite> delete from t where rowid < (select rowid from t limit 2,1);
sqlite> select * from t;
a3
a4
少年亿悲伤 2024-08-14 08:21:24

http://www.sqlite.org/lang_delete.html

如果您有 SQLite 更新删除限制已启用

Delete from your_table 
where any_filter_you_wanted_as_well 
order by if_you_have_a_preference
limit 1000

http://www.sqlite.org/lang_delete.html

If you had the SQLite update delete limit enabled

Delete from your_table 
where any_filter_you_wanted_as_well 
order by if_you_have_a_preference
limit 1000
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文