SELECT PRODUCT_ID, PRODUCT_NAME, COLOR
FROM PRODUCT_INFO
JOIN ORDER_ITEMS ON (PRODUCT_INFO.PRODUCT_ID = ORDER_ITEMS.PRODUCT_ID)
WHERE QUANTITY = (SELECT MAX(QUANTITY) FROM ORDER_ITEMS)
โจทย์ข้อ 2
Code (SQL)
SELECT COLOR,
(SELECT SUM(QUANTITY) FROM ORDER_ITEMS,ORDERS WHERE ORDER_STATUS = 1) STATUS1,
(SELECT SUM(QUANTITY) FROM ORDER_ITEMS,ORDERS WHERE ORDER_STATUS = 2) STATUS2,
(SELECT SUM(QUANTITY) FROM ORDER_ITEMS,ORDERS WHERE ORDER_STATUS = 3) STATUS3,
(STATUS1+STATUS2+STATUS3) TOTAL
FROM PRODUCT_INFO
JOIN ORDER_ITEMS ON (PRODUCT_INFO.PRODUCT_ID = ORDER_ITEMS.PRODUCT_ID)