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
Post a Comment