Skip to content

Instantly share code, notes, and snippets.

@databraineo
Created August 16, 2019 08:22
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 databraineo/99f947b70ee84b71645fd030276f1a27 to your computer and use it in GitHub Desktop.
Save databraineo/99f947b70ee84b71645fd030276f1a27 to your computer and use it in GitHub Desktop.
Code examples for SQL 1x1 blog-article - 16
SELECT
Genre,
count(InvoiceId) AS Anzahl,
avg(AnzahlProKauf) AS MWAnzahlProKauf
FROM (
SELECT
InvoiceId,
c.Name AS Genre,
count(a.TrackId) AS AnzahlProKauf
FROM InvoiceLine a
INNER JOIN Track b ON a.TrackId=b.TrackId
LEFT JOIN Genre c ON b.GenreId=c.GenreId
GROUP BY InvoiceId, b.GenreId
)
GROUP BY Genre
ORDER BY avg(AnzahlProKauf) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment