在oracle中,不支持类似mysql的limit功能,但与之相似的有rownum,能够返回固定行,当配合group by语句时,需要嵌套子查询,因为rownum是在查询结果集上作用。
例题详见leetcode 586.订单最多的客户
https://leetcode.cn/problems/customer-placing-the-largest-number-of-orders/
SELECT customer_number as "customer_number"
FROM (
SELECT customer_number
FROM Orders
GROUP BY customer_number
ORDER BY count(*) DESC
)
WHERE ROWNUM = 1;