HAVING
๋ฐ์ดํฐ๋ฅผ ํํฐ๋งํ๊ธฐ ์ํ ๊ตฌ๋ฌธ
๊ธฐ๋ณธ ๋ฌธ๋ฒ
SELECT
select_list
FROM
table_name
WHERE
search_condition
GROUP BY
group_by_expression
HAVING
group_condition;
WHERE๊ณผ ์ฐจ์ด
๊ฒฐ๊ณผ๋ง ๋ณด๋ฉด where๊ณผ ๋น์ทํ๋ค๊ณ ์๊ฐ ํ ์๋ ์์ง๋ง having์ group by ๋ค์ ์์นํด์ ๊ทธ๋ฃนํํ ๋ฐ์ดํฐ์ ๋ํด ์กฐ๊ฑด์ ์ฃผ๊ณ where์ ๋ชจ๋ ํ๋์ ๋ํด ์กฐ๊ฑด์ ์ค ์ ์๋ค.
์คํ ์์๋ where์ group by์ ์ ์กฐ๊ฑด์ ๊ฑธ๊ณ , having์ group byํ์ ์กฐ๊ฑด์ ๊ฑด๋ค.
์ฌ์ฉ ์
SELECT
ordernumber,
SUM(quantityOrdered) AS itemsCount,
SUM(priceeach*quantityOrdered) AS total
FROM
orderdetails
GROUP BY
ordernumber
HAVING
total > 1000;
orderdetails ํ ์ด๋ธ์์ ordernumber๋ก ๊ทธ๋ฃนํ์ ํ ๋ฐ์ดํฐ๋ค ์ค total์ด 1000์ด์์ธ ๋ฐ์ดํฐ๋ค select
Last updated