mysql中having的例子_mysqlgroupby/having/distinct查询使用例子_MySQL
表的內容如下:
//查詢單分數最高的人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)<140;
//查詢總平均分在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)<140 and avg(score) <80;
//查詢總分。。的學生人數。
select distinct count( stuid) from stu_select_class group by stuid having sum(score)<140 and avg(score) <80;
//查詢。。。的學生人數
select count(distinct stuid) from stu_select_class where classname='english' and score <100;
本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴
本文系統來源:php中文網
TAG標簽:例子
總結
以上是生活随笔為你收集整理的mysql中having的例子_mysqlgroupby/having/distinct查询使用例子_MySQL的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA缓存 Cache类
- 下一篇: java数据库的优化_用Java向数据库