Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active Nov 9, 2018
Embed
What would you like to do?
SQL for Beginner - Solutions Group By
-- QUIZ 1
-- count number of songs by genre
SELECT
genres.name,
COUNT(*) AS n
FROM genres
JOIN tracks
ON genres.genreid = tracks.genreid
GROUP BY genres.name;
-- QUIZ 2
-- sum invoices by country
SELECT
customers.country,
SUM(total) AS sum_invoice
FROM customers
JOIN invoices
ON customers.customerid = invoices.customerid
GROUP BY customers.country;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment