" row_number()over的替代方案(分区by"

时间:2016-09-23 16:50:54

标签: sql-server

寻找下面查询的替代方案
没有row_number() over(partition by

select *,row_number() over(partition by [Tag Name],[PRD] order by [Start Time]) num
from [PRD Project].[Data].[efan1]

2 个答案:

答案 0 :(得分:0)

我们可以尝试使用标识列创建table变量,并在此处插入所选数据以获取row_number作为输出

declare @test table (i int identity(1,1), test varchar(10))

答案 1 :(得分:0)

虽然我认为In [306]: B[~A]='' In [307]: B Out[307]: array(['eggs', '', 'cheese'], dtype='<U6') 可能是最好的方法,但这里有一个替代方案。

设置:

ROW_NUMBER

查询:

 CREATE TABLE [#test] ([Col1] CHAR(1) -- This is what we're partitioning by
                     , [Col2] INT);   -- This is what we're ordering by

 INSERT INTO [#test]
 SELECT CHAR(ABS(CHECKSUM(NEWID()))%16+65) -- Random single letters A:P
      , ABS(CHECKSUM(NEWID())) % 1000      -- Random numbers 1:1000
 FROM [sys].[objects];