[英]How to count rows in mysql subquery
I have two tables course and registered_course我有两张桌子课程和注册课程
course table课程表
crid![]() |
crname![]() |
crlevel![]() |
---|---|---|
1 ![]() |
math![]() |
senior![]() |
2 ![]() |
english![]() |
senior![]() |
3 ![]() |
physics![]() |
senior![]() |
Registered course table注册课程表
id ![]() |
crid![]() |
student_id![]() |
---|---|---|
1 ![]() |
2 ![]() |
25 ![]() |
2 ![]() |
2 ![]() |
26 ![]() |
3 ![]() |
3 ![]() |
23 ![]() |
4 ![]() |
3 ![]() |
24 ![]() |
5 ![]() |
3 ![]() |
27 ![]() |
so i want to achieved this result the first table join with second table and a count of students that registered a subject just like below thanks所以我想实现这个结果,第一个表与第二个表连接,以及注册科目的学生人数,如下所示,谢谢
crname![]() |
crlevel![]() |
number_of_student ![]() |
---|---|---|
math![]() |
senior![]() |
2 ![]() |
physic![]() |
senior![]() |
3 ![]() |
SELECT table1.crname, table1.crlevel, count(table2.studentid)
FROM table1
INNER JOIN table2 ON table1.crid = table2.crid
GROUP BY table1.crname, table1.crlevel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.