【发布时间】:2011-09-04 18:44:35
【问题描述】:
我正在使用 Oracle。
假设我有一个包含这个样本的表格,随机的,内容:
columnA | columnB | content
--------------------------------
AfBkxZ | 292 | a
LDglkK | 181 | b
AfBkxZ | 51 | c
AfBkxZ | 315 | d
LDglkK | 808 | e
Cee89g | 1 | f
我想有一个视图,其中我对 columnA 中的每个值都有一个唯一编号,并在 columnA 具有该值的行内记录编号。
根据上面的示例数据想要的结果:
Group_number | Record_number | columnB | content
------------------------------------------------
1 | 2 | 292 | a (1.2)
3 | 1 | 181 | b (3.1)
1 | 1 | 51 | c (1.1)
1 | 3 | 315 | d (1.3)
3 | 2 | 808 | e (3.2)
2 | 1 | 1 | f (2.1)
我可以通过row_number() over (partition by columnA order by columnB asc)获取record_number。
我如何获得group_number,它实际上是旧columnA 的友好排序别名?
谢谢。
【问题讨论】:
标签: sql oracle analytic-functions