Skip to content

Instantly share code, notes, and snippets.

@JKetelaar
Created October 25, 2019 23:21
Show Gist options
  • Save JKetelaar/223f834700163dbca84992c1b97691f2 to your computer and use it in GitHub Desktop.
Save JKetelaar/223f834700163dbca84992c1b97691f2 to your computer and use it in GitHub Desktop.
SELECT
t.Name AS TrackName,
(t.Milliseconds / 1000) AS Seconds
FROM
Track AS t
WHERE Milliseconds > (
SELECT
Milliseconds
FROM
Invoice
NATURAL JOIN InvoiceLine
LEFT JOIN Track ON Track.TrackId = InvoiceLine.TrackId
GROUP BY
InvoiceLine.TrackId
ORDER BY
COUNT(*)
DESC,
Milliseconds DESC
LIMIT 0,1
) ORDER BY Milliseconds;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment