【发布时间】:2015-03-29 11:45:33
【问题描述】:
我有一个 SQL 问题。以下是我的数据和查询
select ID from table
ID
4
4
5
3
5
3
3
我应该将什么查询添加到我的选择列表中,以便它为每个特定行提供一个值(我不想要总计数,我想要类似出现排名的东西)。
4 1--this is the first time we got a 4 in the list, so 1
4 2--this is the second time we got a 4 in the list, so 2
5 1--this is the first time we got a 5 in the list, so 1
3 1--this is the first time we got a 3 in the list, so 1
5 2--this is the second time we got a 5 in the list, so 2
3 2--this is the second time we got a 3 in the list, so 2
3 3--this is the third time we got a 3 in the list, so 3
【问题讨论】:
-
可能类似于[模式计算][1] [1]:stackoverflow.com/questions/11223003/…
-
这是针对 MySQL 的,我认为这里没有任何帮助。 :(史蒂夫已经搞定了。
-
没那么简单。
row_number()是正确的方向,但要匹配预期的输出,诀窍是保留原始行顺序。
标签: sql-server