これが私のSQLクエリです。テーブル A がありますが、このテーブルを HAVING (A.CATEGORY) に使用しようとすると、エラーが表示されますORA-00979: not a GROUP BY expression
。逆に、テーブル A のすべてのコードを同じ場所にコピーすると機能します。このクエリを最初の方法でうまく動作させるにはどうすればよいですか? ありがとう
最初 (正しくない):
SELECT
DEMO_PRODUCT_INFO.PRODUCT_NAME
FROM
DEMO_PRODUCT_INFO,
(SELECT
DEMO_PRODUCT_INFO.CATEGORY
FROM
DEMO_PRODUCT_INFO
HAVING
MAX(DEMO_PRODUCT_INFO.LIST_PRICE)
= (SELECT MAX(MAX(DEMO_PRODUCT_INFO.LIST_PRICE))
FROM DEMO_PRODUCT_INFO
GROUP BY DEMO_PRODUCT_INFO.CATEGORY)
GROUP BY
DEMO_PRODUCT_INFO.CATEGORY) A
WHERE
DEMO_PRODUCT_INFO.CATEGORY = A.CATEGORY
HAVING
MIN(DEMO_PRODUCT_INFO.LIST_PRICE)
= (SELECT MIN(DEMO_PRODUCT_INFO.LIST_PRICE)
FROM DEMO_PRODUCT_INFO
WHERE DEMO_PRODUCT_INFO.CATEGORY = A.CATEGORY
GROUP BY DEMO_PRODUCT_INFO.CATEGORY)
GROUP BY
DEMO_PRODUCT_INFO.PRODUCT_NAME
2 番目 (正しい):
SELECT
DEMO_PRODUCT_INFO.PRODUCT_NAME
FROM
DEMO_PRODUCT_INFO,
(SELECT
DEMO_PRODUCT_INFO.CATEGORY
FROM
DEMO_PRODUCT_INFO
HAVING
MAX(DEMO_PRODUCT_INFO.LIST_PRICE)
= (SELECT MAX(MAX(DEMO_PRODUCT_INFO.LIST_PRICE))
FROM DEMO_PRODUCT_INFO
GROUP BY DEMO_PRODUCT_INFO.CATEGORY)
GROUP BY
DEMO_PRODUCT_INFO.CATEGORY) A
WHERE
DEMO_PRODUCT_INFO.CATEGORY = A.CATEGORY
HAVING
MIN(DEMO_PRODUCT_INFO.LIST_PRICE)
= (SELECT MIN(DEMO_PRODUCT_INFO.LIST_PRICE)
FROM DEMO_PRODUCT_INFO
WHERE DEMO_PRODUCT_INFO.CATEGORY
= (SELECT DEMO_PRODUCT_INFO.CATEGORY
FROM DEMO_PRODUCT_INFO
HAVING MAX(DEMO_PRODUCT_INFO.LIST_PRICE)
= (SELECT MAX(MAX(DEMO_PRODUCT_INFO.LIST_PRICE))
FROM DEMO_PRODUCT_INFO
GROUP BY DEMO_PRODUCT_INFO.CATEGORY)
GROUP BY DEMO_PRODUCT_INFO.CATEGORY)
GROUP BY DEMO_PRODUCT_INFO.CATEGORY)
GROUP BY
DEMO_PRODUCT_INFO.PRODUCT_NAME