As capable as SQL is, sometimes it's easier to get something done with a python script. It's super easy to connect to an SQLite database from python with the sqlite3 module in the standard library and do whatever you need.
import sqlite3
con = sqlite3.connect("cc.db")
cur = con.cursor()
res = cur.execute("<query>")
rows = res.fetchall()
...