mysql - Joining tables in SQL including count data -


this question has answer here:

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

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -