所以我有以下选择行
,RANK() OVER (Partition by sd.Last_Secondary_School_Provider_Key ORDER BY SUM([EFTS_Consumed]) DESC) AS Rank
选择排名很好,但我想知道在这个排名栏中我可以排名column2 = 'Auckland University of Tehcnology'
吗?
e.g。在排名中,'Auckland University of Tehcnology'
可能会以4为单位,我可以将排名列中的所有行添加到4中吗?
因此,对于以下示例数据,我希望'Rank'
列中的所有记录计算为4:http://imgur.com/aEzYlPb
干杯:)
答案 0 :(得分:0)
你可以这样做:
;with sub as
(
... your query ...
)
, rnk as
(
select top 1 [Rank]
from sub
where Last_Secondary_School_Provider_Key = 'Auckland University of Technology'
)
select sub.col1,
sub.col2,
sub.col3,
sub.col4, -- select all cols from sub except rank
rnk.[Rank] -- and select rank from the rnk block
from sub
cross join rnk;