我的问题与此链接中发布的问题非常相似-如何在没有临时表的SQL查询中为组添加序列号
但是,我需要枚举组的出现。最终的输出是这样的:
Record Group GroupSequence -------|---------|-------------- 1 Chickens 1 2 Chickens 2 3 Cows 1 4 Horses 1 5 Horses 2 6 Horses 3
另外,这必须在Oracle 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会为您提供所需的输出。
GroupSequence1
GroupSequence2
GroupSequence3