次の 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、またはそれ以上の行があるかもしれません