[英]Oracle SQL: Display row number for rows grouped by a column
I have the following dataset: 我有以下数据集:
What I would like is for this result: 我想要的是这个结果:
I've tried using DENSE_RANK but got nowhere fast. 我已经尝试过使用DENSE_RANK,但是速度很快。 I've read through a few stack overflow pages but am now staring at a blank sheet as I can't get anything to work.
我已经阅读了一些堆栈溢出页面,但由于无法进行任何操作,现在正盯着一张空白纸。
Any ideas? 有任何想法吗? Pointers?
指针?
EDIT 编辑
This seems to be ok so far - any obvious issues? 到目前为止,这似乎还可以-有明显的问题吗?
SELECT Person_id,
PERSON_NUMBER,
EFFECTIVE_START_DATE,
EFFECTIVE_END_DATE,
ROW_NUMBER() OVER (PARTITION BY Person_id ORDER BY Person_id) YEAH
FROM PER_ALL_PEOPLE_F
If my assumption is right then you want to fetch the individual person's record in chronological order. 如果我的假设正确,那么您想按时间顺序获取个人的记录。
SELECT
PERSON_ID,
PERSON_NUMBER,
EFFECTIVE_START_DATE,
EFFECTIVE_END_DATE,
ROW_NUMBER() OVER(
PARTITION BY PERSON_ID
ORDER BY
EFFECTIVE_START_DATE
) YEAH
FROM
<YOUR TABLE>
ORDER BY PERSON_ID, YEAH
Note: I know this table and even worked on it. 注意:我知道这张桌子,甚至在上面工作。 Please edit your question and remove the table name from your question.
请编辑您的问题,然后从问题中删除表名。 It's a bad practice to reveal the table name on the WEB.
在WEB上显示表名是一个坏习惯。 Column names are fine but not a table name.
列名很好,但表名不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.