Created
January 28, 2018 04:28
-
-
Save palmerj/6920d2783ef940d10e3e059355eb8e97 to your computer and use it in GitHub Desktop.
SQLite3 - Generate histogram using date ranges and ASCII bar
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
-- On MacOSX installed SQLite3 to get log function support | |
-- brew reinstall sqlite3 --with-functions | |
SELECT load_extension('/usr/local/opt/sqlite/lib/libsqlitefunctions'); | |
SELECT | |
DR.start_datetime as date, | |
COUNT(*) AS total, | |
replace(substr(quote(zeroblob((log(COUNT(*)) + 1) / 2)), 3, log(COUNT(*))), '0', '*') AS bar | |
FROM | |
kx_exports EXP | |
LEFT OUTER JOIN date_ranges DR | |
ON EXP.created_at BETWEEN DR.start_datetime AND DR.end_datetime | |
GROUP BY | |
DR.start_datetime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment