MYSQL calculates the number of students in a class.

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.