1) WHERE 절에서 사용
SELECT * FROM tbl_cake WHERE price >= (SELECT AVG(price) FROM tbl_cake);
2) HAVING 절에서 사용
SELECT code, MIN(arrival) FROM tbl_stock GROUP BY code
HAVING MIN(arrival) < (SELECT AVG(shipment) FROM tbl_stock);
HAVING MIN(arrival) < (SELECT AVG(shipment) FROM tbl_stock);
3) FROM 절에서 사용
SELECT MIN(price)
FROM (SELECT * FROM tbl_cake WHERE price >= 2500) AS c_price;
FROM (SELECT * FROM tbl_cake WHERE price >= 2500) AS c_price;
* 응용
INSERT INTO tbl_advance SELECT * FROM tbl_results
WHERE point1 + point2 > (SELECT AVG(point1 + point2) FROM tbl_results);
UPDATE tbl_allowance SET total = (overtime + travel)
WHERE overtime + travel < (SELECT MAX(overtitme) FROM tbl_allowance);
DELETE FROM tbl_allowance WHERE travel > (SELECT AVG(travel)
FROM tbl_allowance WHERE overtime >= 40000);
WHERE point1 + point2 > (SELECT AVG(point1 + point2) FROM tbl_results);
UPDATE tbl_allowance SET total = (overtime + travel)
WHERE overtime + travel < (SELECT MAX(overtitme) FROM tbl_allowance);
DELETE FROM tbl_allowance WHERE travel > (SELECT AVG(travel)
FROM tbl_allowance WHERE overtime >= 40000);