Hello,
why is my answer not registering as correct?
WITH playlist_info AS
(
SELECT
DISTINCT p.playlist_id,
p.name playlist_name,
tr.name,
CAST(tr.milliseconds * 0.00100 AS FLOAT) length_seconds
FROM playlist p
LEFT JOIN playlist_track pt ON
p.playlist_id = pt.playlist_id
LEFT JOIN track tr ON
pt.track_id = tr.track_id
)
SELECT playlist_id, playlist_name, COUNT(name) number_of_tracks, SUM(length_seconds) length_seconds
FROM playlist_info
GROUP BY playlist_id, playlist_name
ORDER BY playlist_id ASC;
I looked at the answer provided by DataQuest, and the outputs look the same.
This is very much a precision related issue because of float values.
For example, your code might get a value like 501094.9570000001, but their code would get 501094.95700000005. The Grader is not currently equipped to handle that kind of difference, I believe, for this particular exercise.
The difference is that they divide by 1000 and you multiply with 0.00100. Both are the same, but it messes up however the float arithmetic is handled under the hood by SQL.
I would recommend:
To pass the Screen, change from that multiplication to division. The rest of your code seems fine.
Provide feedback to DQ about this using the ? button in the top-right corner of the Classroom. It’s a minor thing, but, hopefully, they look into it at some point.
thank you for your help! changing the 1000 to 1000.0 worked like a charm!
WITH playlist_info AS
(
SELECT
DISTINCT p.playlist_id,
p.name playlist_name,
tr.name,
CAST(tr.milliseconds / 1000.0 AS FLOAT) length_seconds
FROM playlist p
LEFT JOIN playlist_track pt ON
p.playlist_id = pt.playlist_id
LEFT JOIN track tr ON
pt.track_id = tr.track_id
)
SELECT playlist_id, playlist_name, COUNT(name) number_of_tracks, SUM(length_seconds) length_seconds
FROM playlist_info
GROUP BY playlist_id, playlist_name
ORDER BY playlist_id ASC;