Oracle:如何编写SQL查询以显示每组相同值的序列号?

问题描述 投票:-7回答:1

例如,如果我有一个像EmpID,Empname,Country这样的表

输出应该是这样的

EmpId   EmpName Country Serial No.
1       ABC     India         1
2       BCD     India         2
3       CMO     India         3
4       DIS     China         1
5       FGH     China         2
6       FHI     Singapore     1
7       XYZ     Singapore     2
8       KLM     Singapore     3
9       NOP     Singapore     4
10      QRS     Singapore     5

这里按价值分组是国家。

sql oracle
1个回答
1
投票

我自己找到了答案。以下查询可以。

SELECT EmpID , EmpName, Country , ROW_NUMBER() OVER(PARTITION BY
Country order by EmpName ) AS GroupSequence1 from Employee;

我们欢迎进一步的优化

© www.soinside.com 2019 - 2024. All rights reserved.