Created
December 23, 2011 13:21
-
-
Save folkengine/1514196 to your computer and use it in GitHub Desktop.
SQL count plus distinct
This file contains 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
SELECT | |
DISTINCT thing1, (select count(B.thing1) from table1 B where A.thing1 = B.thing1) as mycount | |
FROM | |
table1 A | |
INNER JOIN | |
table2 E on A.table2s_id = e.table2_id | |
WHERE | |
( e.bool = 0 ) | |
GROUP BY | |
A.thing1 | |
ORDER BY | |
mycount DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment