ホームページ  >  記事  >  データベース  >  mysqlgroupby/having/distinct查询使用例子_MySQL

mysqlgroupby/having/distinct查询使用例子_MySQL

WBOY
WBOYオリジナル
2016-06-01 12:59:331348ブラウズ

表的内容如下:

\

//查询单分数最高的人ID

select stuid,max(score) from stu_select_class;

// 查询各科总分2-3名的学生
select stuid, sum(score) from stu_select_class group by stuid limit 1,2;

//查询每科的最高分学生
select classname,stuid,max(score) from stu_select_class group by classname;

//查询总分低于140的学生
select stuid, sum(score) from stu_select_class group by stuid having sum(score)

//查询总平均分在60-80的学生
select stuid, avg(score) from stu_select_class group by stuid having avg(score) between 60 and 80;

//查询。。。。的学生
select stuid, sum(score),avg(score) from stu_select_class group by stuid having sum(score) //查询总分。。的学生人数。
select distinct count( stuid) from stu_select_class group by stuid having sum(score) //查询。。。的学生人数
select count(distinct stuid) from stu_select_class where classname='english' and score

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