sql - How to count the number of students taught by each teacher? -


i have database has following tables

courses: courseid*, coursename, teacherid teachers: teacherid*, teachername students: studentid*, studentname studentcourses: courseid*, studentid* 

legend: * primary key.

how can write query produces produces number of students taught each teacher?

for example

teachername, count bob 15 sarah 5 zubair 1 

edit

select "teachername", count(*) courses inner join teachers on courses."teacherid" = teachers."teacheri" join sutdentcourses on sutdentcourses."courseid" = courses."courseid" group "teachername" order "teachername"; 

you need make join between tables teachers, courses , studentcourses, group records teachername , count studentid.

select teachername, count(studentid) teachers join courses using(teacherid) join studentcourses using(courseid) group teachername 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -