首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

跪求sql

2012-06-21 
跪求sql,在线等test表结构如下id,shopID44 145 349 450 853 4如何写sql语句,才能在查询结果构造字段seq,使

跪求sql,在线等
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  test
[解决办法]
SQL code
select row_number() over(order by id,shopID ) as seq, id,shopID  from [test ] order by id,shopID
[解决办法]
SQL code
SELECT ROW_NUMBER() OVER (ORDER BY ID) AS SEG,*FROM TESTORDER BY ID
[解决办法]
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*/
[解决办法]
探讨
sql server是 2000版本,没有row_number函数,谢谢

[解决办法]
SQL code
select id=identity(int,1,1), id,shopID into #tb from testselect * from #tb
[解决办法]
改变表结构
alter table test add seq int identity(1,1)
[解决办法]
5楼是正解

热点排行