本节涉及SQL语句:
-- 分组查询 SELECT deptno,AVG(sal) FROM t_emp GROUP BY deptno; -- 四舍五入 SELECT deptno,ROUND(AVG(sal)) FROM t_emp GROUP BY deptno; -- 逐级分组 SELECT deptno,job,COUNT(*),AVG(sal) FROM t_emp GROUP BY deptno,job ORDER BY deptno; -- 对分组结果再次汇总计算 SELECT deptno,COUNT(*),SUM(sal),MAX(sal),MIN(sal) FROM t_emp GROUP BY deptno WITH ROLLUP;