Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active November 9, 2018 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyeiei/eadb6ad73657e2da44ebdf935a746711 to your computer and use it in GitHub Desktop.
Save toyeiei/eadb6ad73657e2da44ebdf935a746711 to your computer and use it in GitHub Desktop.
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