我的问题是非常相似的一个张贴在这个环节- 如何在SQL查询中添加序列号组,而不用临时表
但是,我需要枚举组的发生。 最后的输出是这样的:
Record Group GroupSequence
-------|---------|--------------
1 Chickens 1
2 Chickens 2
3 Cows 1
4 Horses 1
5 Horses 2
6 Horses 3
加上这在甲骨文的SQL工作要做。 有任何想法吗?
也许是这样的:
SELECT
ROW_NUMBER() OVER(PARTITION BY [Group] ORDER BY Record) AS GroupSequence1,
RANK() OVER(PARTITION BY [Group] ORDER BY Record) AS GroupSequence2,
DENSE_RANK() OVER(PARTITION BY [Group] ORDER BY Record) AS GroupSequence3,
Table1.Group,
Table1.Record
FROM
Table1
GroupSequence1
, GroupSequence2
和GroupSequence3
会得到你想要的输出。
文章来源: How to add sequence number for each element in a group using a SQL query without temp tables