17_MySQL分组查询的应用

 

 本节涉及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;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2020-11-10 21:09  止一  阅读(98)  评论(0编辑  收藏  举报