如何删除具有特定行号的数据(sqlite) [英] How can I delete data with specific row number (sqlite)

查看:34
本文介绍了如何删除具有特定行号的数据(sqlite)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子 people(姓名、地址、电话),我的桌子有 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?

推荐答案

我假设您想删除前 1000 行"给定select"查询结果的未排序顺序,没有排序参数和条件,其中如果你做错了什么.

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.

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

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

这篇关于如何删除具有特定行号的数据(sqlite)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆