Created
May 26, 2017 15:24
-
-
Save ebuildy/6a508d0e4e9d89d26ba199cd587f260d to your computer and use it in GitHub Desktop.
Get top N records of group by, with Facebook PrestoDB against Hive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * FROM ( | |
SELECT *, RANK() OVER (PARTITION BY day, month ORDER BY hits DESC) AS row_number FROM ( | |
SELECT country AS value, COUNT(*) AS hits, day, month | |
FROM hits_table | |
WHERE year = 2017 | |
GROUP BY country, month, day | |
HAVING COUNT(*) > 1000 | |
ORDER BY month, day, COUNT(*) DESC | |
) | |
) | |
WHERE row_number <= 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment