Created
February 12, 2023 06:58
-
-
Save michael-simons/c2a8e639e540ce928e968d5c1ab8e181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sqlite3 :memory: \ | |
'.mode csv' \ | |
'.import "|curl -s https://gist.githubusercontent.com/zhonglism/f146a9423e2c975de8d03c26451f841e/raw/f79e190df4225caed58bf360d8e20a9fa872b4ac/vgsales.csv" hlp' \ | |
" | |
WITH vgsales AS ( | |
SELECT name, cast(global_sales as number) * 1000000 AS sales, cast(year as number) AS year FROM hlp WHERE year != 'N/A' | |
), | |
per_year AS ( | |
SELECT year, name, sales, dense_rank() OVER (PARTITION BY year ORDER BY sales DESC) AS rnk FROM vgsales | |
) | |
SELECT year, rnk, name, sales FROM per_year WHERE rnk <= 3 AND year >= 2010 ORDER BY year ASC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment