Home > Backend Development > PHP Tutorial > MYSQL 统计一个班有多少个学生

MYSQL 统计一个班有多少个学生

WBOY
Release: 2016-06-20 12:35:22
Original
1991 people have browsed it

create temporary table classname    select 1 as cid, '小一班' as cid_name    union all select 2, '小二班'    union all select 3, '小三班'    union all select 4, '中一班'    union all select 5, '中二班'    union all select 6, '中三班'    union all select 7, '大一班'    union all select 8, '大二班';
Copy after login

create temporary table temp2    select 1 as sid, '张一' as sid_name, 2 as cid    union all select 2, '张二', 1    union all select 3, '张三', 1    union all select 4, '张四', 3    union all select 5, '张五', 2    union all select 6, '张六', 5    union all select 7, '张七', 6    union all select 8, '张八', 6;
Copy after login


SQL联表怎么写?


回复讨论(解决方案)

继续求指点....

SELECT temp2.cid,classname.cid_name,count(temp2.cid) counts,GROUP_CONCAT(temp2.sid_name) names FROM classname,temp2 WHERE classname.cid=temp2.cid GROUP BY temp2.cid;
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template