Wednesday, April 15, 2009

HAVING

SELECT SALES_REGION, AVG(REVENUE)
FROM ACCOUNT
GROUP BY SALES_REGION
HAVING AVG(REVENUE) > 20000

List all SALES_REGION has average revenue greater than 20000

Note that HAVING is condition for group.
This query is NOT valid:
SELECT SALES_REGION, AVG(REVENUE)
FROM ACCOUNT
WHERE AVG(REVENUE) > 20000
GROUP BY SALES_REGION

No comments:

Post a Comment

Oracle Query