"Using subquery, list all product (product number, brand, and category) whose overall number of orders (containing that product) is greater than 500"
Before sub-query I tried using a join:
SELECT PRODUCT.PRODUCT_NO, PRODUCT.BRAND,PRODUCT.PRODUCT_CATEGORY
FROM PRODUCT JOIN ORDERLINE
ON PRODUCT.PRODUCT_NO = ORDERLINE.PRODUCT_NO
WHERE SUM(ORDERLINE_NO) >= 500 ;
And got the following error;
ORA-00934: group function is not allowed here 00934. 00000 - "group function is not allowed here" *Cause: *Action: Error at Line: 28 Column: 6
You are almost there but since you've used aggregate function, you must have a GROUP BY
clause and a HAVING
clause to filter the aggregated result:
SELECT PRODUCT.PRODUCT_NO,
PRODUCT.BRAND,
PRODUCT.PRODUCT_CATEGORY
FROM PRODUCT JOIN ORDERLINE ON PRODUCT.PRODUCT_NO = ORDERLINE.PRODUCT_NO
GROUP BY PRODUCT.PRODUCT_NO,
PRODUCT.BRAND,
PRODUCT.PRODUCT_CATEGORY
HAVING COUNT(ORDERLINE_NO) >= 500 ;
And use COUNT()
instead of SUM()
.
Try this:
not sure if this is what you want
SELECT PRODUCT.PRODUCT_NO, PRODUCT.BRAND,PRODUCT.PRODUCT_CATEGORY
FROM PRODUCT JOIN ORDERLINE
ON PRODUCT.PRODUCT_NO = ORDERLINE.PRODUCT_NO
GROUP BY PRODUCT.PRODUCT_NO, PRODUCT.BRAND,PRODUCT.PRODUCT_CATEGORY
HAVING COUNT(ORDERLINE_NO) >= 500 ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.