求个SQL语句,不要选择集合的第一条记录。

JGH8041 2007-12-18 09:38:53
求个SQL语句,不要选择集合的第一条记录。
...全文
101 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
JL99000 2007-12-19
  • 打赏
  • 举报
回复
愁人啊
arrow_gx 2007-12-18
  • 打赏
  • 举报
回复
真的搞不懂LZ的意思,孩子是不要第一条吗? 有什么条件呢,没有的话,有N多写法,下面几句都可以



select * from tb where id <max(id) order by id desc

select * from tb where id >min(id) order by id

select * from tb where id not in (select min(id) from tb) order by id

select * from tb where id not in (select max(id) from tb) order by id desc




dawugui 2007-12-18
  • 打赏
  • 举报
回复
这是啥意思?

select * from tb where id not in (select top 1 id from tb)
-狙击手- 2007-12-18
  • 打赏
  • 举报
回复
create table ta(id int,[name] char(4),type char(1) ,[money] numeric(12,2)) 
insert ta select 1,'aa','A',120
insert ta select 2,'ab','B',130
insert ta select 3,'ac','C',140
insert ta select 4,'ac','C',130
insert ta select 5,'ac','C',120
go


select *
from ta a
where id <> (select min(id) from ta )
drop table ta
/*

id name type money
----------- ---- ---- --------------
2 ab B 130.00
3 ac C 140.00
4 ac C 130.00
5 ac C 120.00

(所影响的行数为 4 行)
*/
benbenkui 2007-12-18
  • 打赏
  • 举报
回复
先对索引列降序排列,再取前面的所有记录
benbenkui 2007-12-18
  • 打赏
  • 举报
回复
select top(n-1) * from tb order by col desc
中国风 2007-12-18
  • 打赏
  • 举报
回复
?
05 row_number()over(order by ID)生成序号不显示第一条
2005:
select *
from
(
select *,row=row_number()over(order by ID) from t)tmp
where
row>1

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧