imagine that I have 2 tables and I would like to calculate the best selling artists:
- music (id, title, barcode)
artists (barcode, artist)
SELECT COUNT(m.barcode) AS sells, m.barcode, artist FROM music m LEFT JOIN artists a ON m.barcode = a.barcode GROUP BY m.barcode ORDER BY sells DESC
This query returns e.g.:
sells | barcode | artist
---------------------------------
1000 123 jdoe
500 223 kloe
100 321 jdoe
How can I calculate that jdoe complexively sold 1100 music?
Thanks in advance for any hint