Skip to content

Instantly share code, notes, and snippets.

@palmerj
Created January 28, 2018 04:28
Show Gist options
  • Save palmerj/6920d2783ef940d10e3e059355eb8e97 to your computer and use it in GitHub Desktop.
Save palmerj/6920d2783ef940d10e3e059355eb8e97 to your computer and use it in GitHub Desktop.
SQLite3 - Generate histogram using date ranges and ASCII bar
-- 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