– 求学生表的学生总人数 select count(*) from tb_stu
– 求学生表的学生年龄总和 select sum(age) from tb_stu
– 查找学生表里年龄最大的数 select min(age) from tb_stu
– 求学生表平均年龄 select avg(age) from tb_stu
– 求学生表里男女生分别的平均年龄 select sex,avg(age) from tb_stu group by sex
– 求学生表男女生姓张的总人数分别是多少 select sex,count(*) from tb_stu where sname like ‘张%’ group by sex
– 求学生表里各个国家地址分别的总和 select address,count(*) from tb_stu group by address
– 查找学生表里地址人数超过1个人的地方 select address from tb_stu group by address having count(*)>1
– where是在过滤后进行分组,having是在分组后过滤 – 查找学生表里男生人数大于1的地方 select address from tb_stu where sex='男’group by address having count(*)>1
数字函数、日期函数:
https://www.runoob.com/mysql/mysql-functions.html
|