晨风

-------------------- 业精于勤,荒于嬉;行成于思,毁于随

导航

SQL查询结果增加序号列

Posted on 2015-01-04 15:48  shenyixin  阅读(8400)  评论(0编辑  收藏  举报
--sql 2000
select 序号 = (select count(1) from tb where 学号 < t.学号) + 1,学号 ,姓名 from tb t

--sql 2005
select 序号 = row_number() over(order by 学号),学号 ,姓名 from tb

--oracle
select row_number() over(order by 学号) 序号,学号 ,姓名 from tb