Screen Link:
https://app.dataquest.io/m/190/building-and-organizing-complex-queries/3/the-with-clause
I’m facing a really hard time trying to understand why my answer is not being accepted by the exercise.
My code:
WITH playlist_info AS
(SELECT
p.playlist_id,
p.name AS playlist_name,
t.name AS track_name,
(t.milliseconds/1000) AS lenght_seconds
FROM playlist AS p
LEFT JOIN playlist_track AS pt ON pt.playlist_id = p.playlist_id
LEFT JOIN track AS t ON t.track_id = pt.track_id)
SELECT
playlist_id, playlist_name,
COUNT(track_name) AS number_of_tracks,
SUM(lenght_seconds) AS lenght_seconds
FROM playlist_info
GROUP BY 1, 2
ORDER BY 1;
Code from the answer:
WITH playlist_info AS
(
SELECT
p.playlist_id,
p.name playlist_name,
t.name track_name,
(t.milliseconds / 1000) length_seconds
FROM playlist p
LEFT JOIN playlist_track pt ON pt.playlist_id = p.playlist_id
LEFT JOIN track t ON t.track_id = pt.track_id
)
SELECT
playlist_id,
playlist_name,
COUNT(track_name) number_of_tracks,
SUM(length_seconds) length_seconds
FROM playlist_info
GROUP BY 1, 2
ORDER BY 1;
The only difference I can detect is that I’m usin “AS” to create the aliases. Is there anything else that I’m missing???