简体   繁体   English

SQL查询将rownum更改为Oracle中的文本更改

[英]SQL Query to change rownum as text changes in Oracle

I'm stuck with a query wherein i need to change rownum or any running serial no. 我遇到了一个查询,其中我需要更改rownum或任何正在运行的序列号。 back to its original value as soon as it founds change of text of second column. 一旦发现第二列文本发生变化,就回到原来的值。 I'm using Oracle 11g. 我正在使用Oracle 11g。

For Eg. 对于Eg。 My Data is 我的数据是

    ________ 
   | EMP_CD |
   |--------| 
   |  D123  |
   |--------| 
   |  D123  | 
   |--------| 
   |  D123  |
   |--------| 
   |  F743  |
   |--------|  
   |  F743  |
   |________|

So Now What I'm expecting is 所以现在我期待的是

 _______ ________ 
| SR NO | EMP_CD |
|-------|--------| 
|   1   |  D123  |
|-------|--------| 
|   2   |  D123  | 
|-------|--------| 
|   3   |  D123  |
|-------|--------| 
|   1   |  F743  |
|-------|--------|  
|   2   |  F743  |
|_______|________|
select row_number() over (partition by emp_cd order by null) as sr_no, emp_cd
from   your_table
order by emp_cd, sr_no;

ORDER BY is optional. ORDER BY是可选的。

You can use the row_number() analytic function: 您可以使用row_number()分析函数:

SELECT ROW_NUMBER() OVER (PARTITION BY emp_cd ORDER BY 1) AS sr_no, emp_cd
FROM   mytable

您可以使用row_number()分析函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM