๋ชฉ๋กWhere (1)

YS's develop story

SQL Having, Where ์ฐจ์ด

SQL Having, Where ์ฐจ์ด ์œ„์™€ ๊ฐ™์ด instructor๋ผ๋Š” ํ…Œ์ด๋ธ”์ด ์žˆ์Šต๋‹ˆ๋‹ค. SELECT dept_name, AVG(salary) AS avg_salary FROM instructor GROUP BY dept_name HAVING AVG(salary) > 42000; ์ง‘๊ณ„ ํ•จ์ˆ˜์™€ GROUP BY ํ‚ค์›Œ๋“œ๋ฅผ ํ™œ์šฉํ•ด ์œ„์™€ ๊ฐ™์€ ์ฟผ๋ฆฌ๋ฌธ์œผ๋กœ dept_name๋ณ„๋กœ ํ‰๊ท  ์—ฐ๋ด‰์„ ์ถœ๋ ฅํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์—ฌ๊ธฐ์„œ ๊ถ๊ธˆํ•œ ๊ฒŒ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค. HAVING์ด ์•„๋‹Œ WHEREํ‚ค์›Œ๋“œ๋กœ ์œ„์™€ ๋˜‘๊ฐ™์ด ์ถœ๋ ฅํ•˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ์š”? ๊ฒฐ๋ก ๋ถ€ํ„ฐ ๋งํ•˜์ž๋ฉด ๊ทธ๋ ‡๊ฒŒ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค! ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์›์„œ์—๋„ ์œ„์™€ ๊ฐ™์ด ๋‚˜์™€ ์žˆ์Šต๋‹ˆ๋‹ค. HAVING์€ ๊ทธ๋ฃน์„ ํ˜•์„ฑ ํ•œ ํ›„์— ์ ์šฉ์ด ๋˜์ง€๋งŒ WHERE๋Š” ๊ทธ๋ฃน์„ ๋งŒ๋“ค๊ธฐ ์ „์— ์ ์šฉ์ด..

Database 2021. 4. 28. 10:24