1.上机题
13:SELECT age,name FROM stu ORDER BY age,NAME ASC;
14:select dizhi,count(*)as 人数 from stu group by dizhi limit 0,1;
15:select * from stu group by dizhi having id>5 limit 0,1;
16:select dizhi,avg(age)as 平均年龄,max(age) as 年龄最大值,min(age)as 年龄最小值 sum(age)as 年龄和 from stu group by dizhi;
17:select dizhi, COUNT(age) as 行数 , SUM(age) as 年龄和, AVG(age)as 平均年龄值 ,MAX(age) as 年龄最大值, MIN(age) as 年龄最小值 from stu group by dizhi;
18:select `name`,LENGTH(name) ,NOW() from stu ;
19:select dizhi,avg(age)as 平均年龄 from stu where age>20 group by dizhi limit 0,1;
20:select dizhi,avg(age)as 平均年龄 from stu where age>20 group by dizhi having count(id)>=5 limit 0,1;
21:select addres,avg(age)as 平均龄 from stu where age>20 group by addres ORDER BY age asc limit 0,1;
2.使用聚合函数查询
1:select count(*)as 人数 from stu;
2:SELECT SUM(score) FROM stu WHERE xuehao=‘2011001003‘;
3:SELECT avg(score) FROM stu WHERE xuehao=‘2011001004‘;
4:SELECT MAX(score)AS 最高成绩,MIN(score)AS 最低成绩, AVG(score)AS 平均分 FROM stu_score WHERE stu_id=‘2‘;
5:SELECT AVG(score) FROM stu_score WHERE stu_id=‘1‘ and score>60;
3.使用分组语句查询
2:SELECT stu_id,AVG(score) from stu_score GROUP BY stu_id;
3:select stu_id,SUM(score) from stu_score GROUP BY stu_id desc;
4:select sex ,COUNT(sex) from xuesheng group by sex ;
5:select banji,COUNT(banji) from stu group by banji;
6:select age,SUM(ks) from stu group by age asc;
原文:https://www.cnblogs.com/Lxf19990923/p/11603117.html