191-7 Why do I get different results?

Hi all,

I am currently stuck at this point of the project. My answer is
no - 498
yes - 116

which is different to the solution’s 114 for yes. Here’s what I’ve written:

trackvsalbum = '''
WITH invoice_track AS
(
SELECT
invoice_id,
MIN(track_id) track_id,
COUNT(track_id) total_invoice_tracks
FROM invoice_line
GROUP BY invoice_id
),

album_track AS
(
SELECT
album_id,
MIN(track_id) album_track_id,
COUNT(track_id) total_album_tracks
FROM track
GROUP BY album_id
),

album_invoice_track AS
(
SELECT
CASE
WHEN total_invoice_tracks = total_album_tracks
AND album_track_id = track_id
THEN ‘yes’
ELSE ‘no’
END AS album_purchase,
COUNT(*) number_of_invoices,
CAST(COUNT(*) AS FLOAT)/CAST((SELECT COUNT(*) FROM invoice) AS FLOAT)*100 percentage
FROM invoice_track it
LEFT JOIN album_track at
ON at.album_track_id = it.track_id
GROUP BY album_purchase

)

SELECT * from album_invoice_track
'''

run_query(trackvsalbum)

Could someone please explain why it is different? Your help will be greatly appreciated.

Thanks

Ting

Hey, Ting.

I used the query provided here to find the invoice classification done by Dataquest’s solution.

I’m attaching it to this reply. You can use this to investigate what invoices are classified differently and then understand why.

dq_invoice_classfication.csv (6.6 KB)