Skip to content

Instantly share code, notes, and snippets.

@alexpetralia
Created September 25, 2016 02:27
Show Gist options
  • Save alexpetralia/d758eae248488052b8c75fd67612bd94 to your computer and use it in GitHub Desktop.
Save alexpetralia/d758eae248488052b8c75fd67612bd94 to your computer and use it in GitHub Desktop.
cnxn = engine.connect()
r = cnxn.execute("""
WITH igm AS (
SELECT economist_name, institution, AVG(confidence) AS avg_conf
FROM igmchicago
GROUP BY economist_name, institution
)
SELECT * FROM igm i
WHERE avg_conf >
(SELECT AVG(avg_conf) FROM igm g WHERE i.institution = g.institution)
ORDER BY institution, avg_conf
""")
r.fetchall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment