一、聚合函数(sum,count,avg,max,min),作用在多条记录上。
1、select sum(population) from country
2、select region ,sum(population) ,sum(count) from country group by region having sum(count)>1000
where在聚合前先筛选记录
group by
having 在聚合后对组记录进行筛选,不能用where对sum(count)>1000进行筛选,因为country表中不存在这样一条记录
查询每个部门各种职位的雇员数
3、select deptno,job,count(*) from emp group by deptno,job
4、select deptno,sum(sal) from emp where sal>1200 group by deptno having sum(sal)>10000 order by deptno