我正在使用postgresql,并且有两列“国家”和“名称”。我想获得每个国家/地区x人的名字。
例如,如果我有这样的数据
lIndex
说我想为每个国家/地区获得2个ppl名称
Name Country
"John" "US"
"Kim" "KR"
"Mike" "US"
"Park" "KR"
"Kim" "US"
"Doe" "RU"
"Pou" "KR"
"John" "RU"
"Sam" "RU"
... ...
... ...
有没有办法做这种事情?
答案 0 :(得分:4)
您可以尝试以下操作-使用row_number()
select * from
(
SELECT Name, Country, row_number() over(partition by country order by name) as rn
FROM [table]
)A where rn<=10 [here x=10]