34,590
社区成员
发帖
与我相关
我的任务
分享
create table #EE(OrderID int)
insert #EE
select 10248 union all
select 10248 union all
select 10249 union all
select 10249 union all
select 10250 union all
select 10250 union all
select 10250 union all
select 10251 union all
select 10251 union all
select 10251 union all
select 10252 union all
select 10252
select row_number() over (order by OrderID)rank,OrderID from #EE
rank OrderID
-------------------- -----------
1 10248
2 10248
3 10249
4 10249
5 10250
6 10250
7 10250
8 10251
9 10251
10 10251
11 10252
12 10252
--2005
select row_number() over (order by orderid,productid),* from 表名
--2000
select (select count(1) from 表名 where orderid<=a.orderid and productid<a.productid)
from 表名 a
declare @tb table(OrderID int)
insert @tb
select 10248 union all
select 10248 union all
select 10249 union all
select 10249 union all
select 10250 union all
select 10250 union all
select 10250 union all
select 10251 union all
select 10251 union all
select 10251 union all
select 10252 union all
select 10252
select row_number() over (order by OrderID) AS ' ',OrderID
from @tb
/*
OrderID
-------------------- -----------
1 10248
2 10248
3 10249
4 10249
5 10250
6 10250
7 10250
8 10251
9 10251
10 10251
11 10252
12 10252
*/
select row_number() over (order by orderid asc),* from
(select * from TB where....(你需要的数据))T
select row_number() over (order by orderid,productid),* from 表名
--或者这样,加一自增列,查询完再去掉。
alter table tb add px int identity(1,1)
select * from tb
alter table tb drop column px
--或者用临时表
select px=identity(int,1,1),* into #temp from tb
select * from #temp
drop table #temp
SELECT ID=IDENTITY(INT,1,1),* INTO #T FROM TB
SELECT * FROM #T