31 Years of Python | 48 Hour Sale Extension!!!
days
hours
minutes
seconds

Building and Organizing Complex Queries 3. The With Clause

Building And Organizing Complex Queries — The With Clause | Dataquest

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.

thank you

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 very much! it still fails after changing to divide by 1000. i will provide feedback to DQ.

Can you share the code you ran after the change?

Because I ran it after the change and it passed without issue. You might have changed something else as well by mistake, perhaps?

Update: I should have been clearer. It’s divided by 1000.0 and not just 1000. Reporting this to them is better.

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;