SQL queries

https://gist.github.com/kjtolsma/fc85add1acd619923c5ff8de13e17f68