我有一张这样的表:
Email | Number
a | 0.5
a | 1
a | 1.1
b | 5
b | 3.7
我想保留相同的表格布局,但要根据“数字”列的排名顺序获取唯一电子邮件的实例编号:
Email | Number | RankOrder
a | 0.5 | 3
a | 1 | 2
a | 1.1 | 1
b | 7.7 | 1
b | 6 | 2
答案 0 :(得分:2)
如果我理解正确,你需要row_number()
函数(这是大多数数据库中可用的ANSI标准函数):
select email, number,
row_number() over (partition by email order by number desc) as rankorder
from t;
答案 1 :(得分:2)
您可以使用窗口Row_Number()
:
Select Email, Number,
Row_Number() Over (Partition By Email Order By Number Desc) As RankOrder
From LikeSo;