Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

sql count matching group by

# To count the number of teachers in each department, including 
# rows where COUNT(t.name) == 0
SELECT d.name,COUNT(t.name) FROM teacher t
RIGHT JOIN dept d ON (t.dept=d.id) GROUP BY d.name;
Source by sqlzoo.net #
 
PREVIOUS NEXT
Tagged: #sql #count #matching #group
ADD COMMENT
Topic
Name
2+9 =