최강의 파워
때로는 쿼리 결과를 ‘저장’해 두고 데이터를 더 가공하고 싶을 때가 있어요. 이를 위해 SQL Server가 다시 시작될 때까지 데이터베이스에 유지되는 임시 테이블을 만들 수 있습니다. 이 마지막 연습에서는 각 앨범에서 가장 긴 트랙을 선택한 뒤, 쿼리의 일부로 생성할 임시 테이블에 그 결과를 추가해 볼 거예요.
이 연습은 강의의 일부입니다
SQL Server 입문
연습 안내
SELECT문을 사용해#maxtracks라는 임시 테이블에 데이터를 INSERT 하세요.artist_id로album과artist를 조인하고,album_id로track과album을 조인하세요.- 마지막으로 새로운 테이블의 모든 열을 가져오는
SELECT문을 실행하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
SELECT album.title AS album_title,
artist.name as artist,
MAX(track.milliseconds / (1000 * 60) % 60 ) AS max_track_length_mins
-- Name the temp table #maxtracks
INTO ___
FROM album
-- Join album to artist using artist_id
INNER JOIN artist ON album.artist_id = artist.artist_id
-- Join track to album using album_id
___
GROUP BY artist.artist_id, album.title, artist.name,album.album_id
-- Run the final SELECT query to retrieve the results from the temporary table
SELECT album_title, artist, max_track_length_mins
FROM #maxtracks
ORDER BY max_track_length_mins DESC, artist;