Does Presto SQL really lack TOP X functionality in SELECT statements?
If so, is there a workaround in the meantime?
https://prestodb.io/
If you simply want to limit the number of rows in the result set, you can use LIMIT
, with or without ORDER BY
:
SELECT department, salary
FROM employees
ORDER BY salary DESC
LIMIT 10
If you want the top values per group, you can use the standard SQL row_number()
window function. For example, to get the top 3 employees per department by salary:
SELECT department, salary
FROM (
SELECT department, salary row_number() OVER (
PARTITION BY department
ORDER BY salary DESC) AS rn
FROM employees
)
WHERE rn <= 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With