- 小教板
-
sql语句删除表中的前面几条记录的重点在于你如何去获取前面的几条记录。
和不同的数据库中也有一些关系
通常有以下几种方式:(样例代码)
1: 简单的 top方式
delete from 表 where id in(select top 3 id from 表)
2:rank排名函数
根据某些业务条件,使用排名函数获得排名靠前的值,再使用删除操作
deletefrom 表 where id in(
select id from(
SELECT id ,RANK() OVER (PARTITION BY i. i.Quantity DESC) AS Rank
FROM表
) where rank<=3
)
- 西柚不是西游
-
这样删不掉应该是你的记录中就是这样写着NULL
要是这样的话你在NULL上加上单引号,这样应该就可以了
delete from student
where s_no="NULL"
如果记录中那一列是空白的,也就是说不是显示NULL,那你把=改成is就可以了
- 北境漫步
-
由于informix的first选项限制较多,不能用在子查询,也不能用在into
temp的select语句中,感觉一个sql写不出来。
用下面的select语句生成一堆delete语句,然后再跑这些delete语句:
select
first
100
"delete
from
tablename
where
rowid="||
rowid
||";"
from
tablename
order
by
begintime;
- 牛云
-
delete from student where s_no is null and s_sex="男"
你再想删除前两条好像就只能完全匹配那么一条一条的删了
你这没有ID列,没办法按ID删
- wpBeta
-
delete from student where s_no is null
delete from student where s_no is null and s_sex = "男"
- 马老四
-
delete from student where s_no is null or s_no=""
- S笔记
-
delete student where id in(select top 5 id from student)
- LuckySXyd
-
直接DELETE TOP (5) FROM student