Presto SQL真的缺少SELECT 语句中的 TOP X 功能吗?
如果是这样,在此期间是否有解决方法?
https://prestodb.io/
如果只想限制结果集中的行数,可以使用 LIMIT
,带或不带ORDER BY
:
SELECT department, salary
FROM employees
ORDER BY salary DESC
LIMIT 10
如果需要每个组的最大值,可以使用标准的 SQL row_number()
窗口函数。例如,要按工资获取每个部门的前 3 名员工:
SELECT department, salary
FROM (
SELECT department, salary, row_number() OVER (
PARTITION BY department
ORDER BY salary DESC) AS rn
FROM employees
)
WHERE rn <= 3