[英]SQL Query to change rownum as text changes in Oracle
我遇到了一個查詢,其中我需要更改rownum或任何正在運行的序列號。 一旦發現第二列文本發生變化,就回到原來的值。 我正在使用Oracle 11g。
對於Eg。 我的數據是
________
| EMP_CD |
|--------|
| D123 |
|--------|
| D123 |
|--------|
| D123 |
|--------|
| F743 |
|--------|
| F743 |
|________|
所以現在我期待的是
_______ ________
| 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是可選的。
您可以使用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.