# 3. 발매일 조건
-- 2010년대에 발매된 노래를 출력하세요.
-- title(노래) composer title(앨범)
SELECT
A.`title`, A.`composer`, B.`title`
FROM
`music` AS A
JOIN `album` AS B
ON A.`albumId` = B.`id`
where -- B.releaseDate >= '2010-01-01' and B.releaseDate < '2020-01-01';
B.releaseDate between '2010-01-01' and '2020-01-01'; -- 끝날짜는 포함되지 않는다.
# 4. 가수별 총 노래 수
-- 가수별 노래 개수를 출력하세요.(singer)
-- 2005년 이전 데뷔 가수는 제외 하세요.(singer)
-- 노래 수 내림 차순으로 출력하세요.
SELECT
A.`name`, A.`debut`, COUNT(1) AS `count`
FROM
`singer` AS `A`
JOIN `music` AS `B`
ON A.`id` = B.`singerId`
WHERE
A.`debut` >= 2005
GROUP BY A.`id`
ORDER BY `count` DESC;
# 5. AKMU 노래
# AKMU 노래를 모두 출력하세요.(singer, album, music)
-- name title playTime album title
SELECT
C.`name`, B.`title`, B.`playTime`, A.`title` AS `album title`
FROM
`album` AS A
JOIN `music` AS B
ON A.`id` = B.`albumId`
JOIN `singer` AS C
ON C.`id` = B.`singerId`
WHERE
C.`name` = 'AKMU';
# 6. 2008년 부터 10년 동안 발매된 노래를 출력하세요.
# 단 재생시간이 4분 이상인 노래만 출력하세요.
# title(music) name(singer) playTime(music) album title(album)
select B.title, A.name, B.playTime, C.title
from singer AS A
join music AS B
on A.id = B.singerId
join album AS C
on B.albumId = C.id
where C.releaseDate between '2008-01-01' and '2019-01-01'
and B.playTime >= 240;
# 7. 앨범별 총 재생 시간
-- 재생시간이 470초과 인 것만 출력하세요.
-- 재생시간 오름 차순으로 출력하세요.
-- name(singer) title(album) tracks(album) playTime(music)
SELECT
A.`name`, B.`title`, C.`tracks`, sum(B.`playTime`) AS `playTime`
FROM
`singer` AS A
JOIN `MUSIC` AS B
ON A.`id` = B.`singerId`
JOIN `album` AS C
ON C.`id` = B.`albumId`
GROUP BY C.`id`
HAVING `playTime` > 470
ORDER BY `playTime` ASC;