一、数据结构
二、需要结果:
三、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