mysql - Joining tables in SQL including count data -
this question has answer here:
- using sql join , count 5 answers
a question came across:
"produce list of department names , number of people in each department?"
there 2 tables, person , department. 1 of fields in person table name. there aren't department names given yet department table, same person, name field empty (no names under name field).
here code:
select department.name department inner join count(name) person;
you can join both tables considering there exist relationship between them. assuming person table has department name
associated it, can use below query count of person per department
select department.name deptname, count(p.name) department d left join person p on d.name = p.department_name group d.name
Comments
Post a Comment