MySQL行列转换与聚合函数

一、数据结构
MySQL行列转换与聚合函数
二、需要结果:
MySQL行列转换与聚合函数
三、MySQL行列转换与聚合函数

SELECT IFNULL(ADMDIVNAME, 'TATOLSUM') AS ADMDIVNAME,
	SUM(IF(STAFF_MANAGE.ORGANTYPECODE ='SYDW', STAFFTOTAL, 0)) AS SYDW_BZ_RS,
	SUM(IF(STAFF_MANAGE.ORGANTYPECODE ='XZJG', STAFFTOTAL, 0)) AS XZJG_BZ_RS,
	SUM(IF(STAFF_MANAGE.ORGANTYPECODE ='SYDW', JOBTOTAL, 0)) AS SYDW_JOB_RS,
	SUM(IF(STAFF_MANAGE.ORGANTYPECODE ='XZJG', JOBTOTAL, 0)) AS XZJG_JOB_RS,
	COUNT(DISTINCT (CASE WHEN STAFF_MANAGE.ORGANTYPECODE ='SYDW' THEN JOBTOTAL END)) AS SYDW_NUM,
	COUNT(DISTINCT (CASE WHEN STAFF_MANAGE.ORGANTYPECODE ='XZJG' THEN JOBTOTAL END)) AS XZJG_NUM
FROM STAFF_MANAGE
GROUP BY ADMDIVNAME
WITH ROLLUP;

抽时间记录,大家共同学习。
https://www.cnblogs.com/weibanggang/p/9679301.html
https://blog.csdn.net/weixin_40683253/article/details/80814085

上一篇:001 SSM框架学习


下一篇:医学四视图-001-基本框架搭建