-- 聚合查询(集函数)
-- 1) count() 返回总记录数
select count(*) from student
-- 查询当前字段的总个数 (null 不计算)
select count(tid) from student
-- 2) max() 最大值
select max(age) from student
-- 3) min()最小值
select min(age) from student
-- 4) sum() 求和
select sum(age) from student
-- 5) avg() 求平均值
select avg(age) from student
-- 请帮我查询年龄最大的学生的信息
-- 普通字段不能和聚合函数放在一起查询 除非 聚合函数和 group by 的字段放一起
-- 或者聚合函数放在子查询中
-- select sname,max(age) from student -- 错误的
select sname,age from student where age=
(select max(age) from student)
-- 查询男生和女生中年龄最大的学生
update student set age=23,sex='女' where sid=7
select sex,max(age) from student group by sex
select * from student
-- 对分组后的结果进行删选 用having
select tid,count(*) from student group by tid having count(*)>2