๐Ÿ’ป [SQL] 14. WITH ์ ˆ

thisk336ยท2023๋…„ 10์›” 11์ผ
0

SQL

๋ชฉ๋ก ๋ณด๊ธฐ
14/17
post-thumbnail

WITH ์ ˆ

  • WITH ๊ตฌ๋ฌธ์€ ์„œ๋ธŒ์ฟผ๋ฆฌ(Subquery)๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ž„์‹œ ํ…Œ์ด๋ธ”์ด๋‚˜ ๋ทฐ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ๋ฌธ์ด๋‹ค.
  • ์„œ๋ธŒ์ฟผ๋ฆฌ ๋ธ”๋ก์— ๋ณ„์นญ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์˜ตํ‹ฐ๋งˆ์ด์ €๋Š” SQL์„ ์ธ๋ผ์ธ ๋ทฐ๋‚˜ ์ž„์‹œ ํ…Œ์ด๋ธ”๋กœ ํŒ๋‹จํ•œ๋‹ค.
  • ๊ธฐ๋ณธ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
WITH [CTE๋ช…] AS (
	SQL ์ฟผ๋ฆฌ
)
CTE๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์ธ ์ฟผ๋ฆฌ
WITH AvgRentalDuration AS (
	SELECT rating, avg(rental_duration)
    FROM film
    GROUP BY rating
)
SELECT * FROM AvgRentalDuration;

0๊ฐœ์˜ ๋Œ“๊ธ€