I have the following query:
SELECT
CASE WHEN ROW_NUMBER() OVER (ORDER BY COUNT(*) desc) <=10 THEN name ELSE, --ignore-- END AS name
COUNT(*) as COUNT
FROM person
GORUP BY name
So I'm simply trying to get top 10 occurencies of a person in the list. But I only want the top 5, are there any ways to make not select lines that falls outside top 5? I know I can make a nested select, but I want to know if it's possible to replace the --ignore-- with something that ignores?
CodePudding user response:
Just use the upper limit of 5
SELECT
CASE WHEN ROW_NUMBER() OVER (ORDER BY COUNT(*) desc) <=10 THEN name ELSE '' END AS name
FROM ...
LIMIT 5