MYSQL calculates the number of students in a class.
Create temporary table classname select 1 as cid, 'small shift 1 'as cid_name union all select 2, 'small shift 2' union all select 3, 'small shift 3 'union all select 4, 'First shift 'Union all select 5, 'second shift 'Union all select 6, 'third shift 'Union all select 7, 'First shift 'Union all select 8, 'sophomore class ';
Create temporary table temp2 select 1 as sid, 'Zhang Yi' as sid_name, 2 as cid union all select 2, 'Zhang 2', 1 union all select 3, 'Zhang San ', 1 union all select 4, 'Zhang Si', 3 union all select 5, 'Zhang Wu', 2 union all select 6, 'Zhang Liu', 5 union all select 7, 'Zhang 7', 6 union all select 8, 'Zhang 8', 6;
How to write SQL join tables?
Reply to discussion (solution)
Continue to seek advice ....
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;