当前位置: 代码迷 >> Sql Server >> ,请协助一下,多谢
  详细解决方案

,请协助一下,多谢

热度:8   发布时间:2016-04-27 12:20:01.0
各位高手,请协助一下,谢谢。
test表结构如下
id,shopID
44 1
45 3
49 4
50 8
53 4
如何写sql语句,才能在查询结果构造字段seq,使结果如下:

seq,id,shopID
1 44 1
2 45 3
3 49 4
4 50 8
5 53 4

谢谢了,各位

------解决方案--------------------
SQL code
select  seq=row_number()over(order by getdate()),*from  tb
------解决方案--------------------
SQL code
create sequence seq;select seq.nextval seq,id,shopID from test;
------解决方案--------------------
探讨
sql server是 2000版本,没有row_number函数,谢谢

------解决方案--------------------
SQL code
select id=identity(int,1,1), id,shopID into #tb from testselect * from #tb
------解决方案--------------------
SQL code
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([id] int,[shopID] int)insert [test]select 44,1 union allselect 45,3 union allselect 49,4 union allselect 50,8 union allselect 53,4select seq=(select COUNT(1)     from test b where b.ID<=a.ID),* from test a/*seq    id    shopID---------------------1    44    12    45    33    49    44    50    85    53    4*/--在另外一个帖子已经恢复,没看见???
  相关解决方案