且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-17 18:58:53

我假设您想删除前 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