日期:2014-05-18  浏览次数:20533 次

在查询的结果集中怎样去掉第一条记录?
记录有很多条,在查询的结果集中只把第一条记录去掉,剩下的记录保留
不是删除第一条记录,而是不显示第一条记录
create table #test1
(
id int

)
insert into #test1 select 1
insert into #test1 select 10
insert into #test1 select 11
insert into #test1 select 15
insert into #test1 select 16
insert into #test1 select 18
insert into #test1 select 19

select * from #test1
drop table #test1

怎样不显示第一条记录

------解决方案--------------------
SQL code

select id from (select row_number()over(order by getdate()) as rownum,* from tbl)a
where rownum>=2

------解决方案--------------------
select * from #test1
except
select top 1 * from #test1
------解决方案--------------------
SQL code
select ID from (
select ROW_NUMBER() over(order by id )rn,* from #test1 )a where rn>1

------解决方案--------------------
select * from #test1
except
select * from #test1 where id=1

--or
select * from #test1
except
select top 1 * from #test1