在PERFORMANCE表中,某些行的PERFORMANCE_INDICATOR列具有相同的值。
ID | PERFORMANCE_INDICATOR | REALISASI |
---------------------------------------------------------
1 | Compliance of Inventory Data Consumer | 90,91 |
7 | Compliance of Inventory Data Consumer | 92,22 |
13 | Compliance of Inventory Data Consumer | 93,31 |
9 | Migrasi ODF to FTM | 90,91 |
3 | Migrasi ODF to FTM | 92,22 |
14 | Migrasi ODF to FTM | 93,31 |我只想选择两个数据每个重复的数据如下所示:
ID | PERFORMANCE_INDICATOR | REALISASI |
-----------------------------------------------------
1 | Compliance of Inventory Data Consumer | 90,91 |
7 | Compliance of Inventory Data Consumer | 92,22 |
9 | Migrasi ODF to FTM | 90,91 |
3 | Migrasi ODF to FTM | 92,22 |我应该使用哪条SQL语句来查找这些行?谢谢你的帮助。
发布于 2018-08-03 15:32:48
使用analytic ROW_NUMBER,然后对其进行过滤:
with cte as (
select your_table.*
, row_number() over (partition by PERFORMANCE_INDICATOR order by ID) as rn
from your_table
)
select ID, PERFORMANCE_INDICATOR, REALISASI
from cte
where rn <= 2
order by PERFORMANCE_INDICATOR, ID
/https://stackoverflow.com/questions/51666898
复制相似问题