Last active
December 23, 2015 06:29
-
-
Save randyzwitch/6594458 to your computer and use it in GitHub Desktop.
Example of SQL formatting
This file contains hidden or 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
#Capitalize reserved keywords, indent between keywords and for multi-line statements | |
#Tables on separate lines | |
#Untested, hopefully this is valid SQL :) | |
SELECT | |
a.key, | |
a.col2, | |
a.col3, | |
COALESCE(a.col4,0) AS col4, | |
b.col5, | |
b.col6, | |
totals.tot_items, | |
totals.tot_cost | |
FROM accounts AS a | |
LEFT JOIN bills AS b ON (a.key = b.key) | |
LEFT JOIN (SELECT | |
col2, | |
SUM(items) AS tot_items, | |
SUM(cost) AS tot_cost | |
FROM items | |
GROUP BY col2) AS totals ON (a.col2 = totals.col2) | |
WHERE a.key in (SELECT key FROM active_accounts WHERE date_utc >= '2013-09-01') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment