我有这个 PL/SQL 查询:
SELECT customer_id, table_id, count(table_id) as reserved
FROM { derived table }
GROUP BY customer_id,table_id
ORDER BY reserved DESC
我有这个结果:
http://i.stack.imgur.com/ATfUw.png
所以现在我想获取前 2 行(根据reserved
列的最大值),我尝试了这个查询:
SELECT customer_id,table_id,max(reserved) from
(
SELECT customer_id, table_id, count(table_id) as reserved
FROM { derived table }
GROUP BY customer_id,table_id
ORDER BY reserved DESC
)
GROUP BY customer_id, table_id
我收到与上述相同的结果...
注意:结果只是示例,下次可能会有 3、1 或更多行具有最大值