ホームページ  >  記事  >  バックエンド開発  >  MYSQL はクラス内の生徒の数を数えます

MYSQL はクラス内の生徒の数を数えます

WBOY
WBOYオリジナル
2016-06-20 12:35:221921ブラウズ

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, '大二班';

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;


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;


声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。