Created
June 18, 2009 17:31
-
-
Save tmilewski/132033 to your computer and use it in GitHub Desktop.
Trying to get the num of faculty assoc w/ a dept incl. the depts w/o any associations
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 d.id as dept_id, d.department, count(f.id) as cnt | |
FROM departments d JOIN faculty f ON f.department_primary = d.id | |
GROUP BY d.department | |
UNION | |
SELECT d.id as dept_id, d.department, 0 as cnt | |
FROM departments d | |
WHERE d.id NOT IN (SELECT DISTINCT(department_primary) FROM faculty) | |
ORDER BY department ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment