简体   繁体   English

如何计算 mysql 子查询中的行数

[英]How to count rows in mysql subquery

I have two tables course and registered_course我有两张桌子课程和注册课程

course table课程表

crid哭泣 crname名称 crlevel等级
1 1 math数学 senior高级的
2 2 english英语 senior高级的
3 3 physics物理 senior高级的

Registered course table注册课程表

id ID crid哭泣 student_id学生卡
1 1 2 2 25 25
2 2 2 2 26 26
3 3 3 3 23 23
4 4 3 3 24 24
5 5 3 3 27 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 number_of_student
math数学 senior高级的 2 2
physic物理 senior高级的 3 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM