SELECT AF_DEPARTMENT, dept.FULLNAME, SUM(CASE AF_CLASSIFY WHEN 1 THEN 1 ELSE 0 END) AS 'o_standard', (COUNT(AF_DEPARTMENT) - SUM(CASE AF_CLASSIFY WHEN 1 THEN 1 ELSE 0 END)) AS 'o_nonstandard', COUNT(AF_DEPARTMENT) AS 'o_total', SUM(IF(isAddInNew = 1 AND AF_CLASSIFY = 1,1,0)) AS 'n_standard', SUM(IF(isAddInNew = 1 AND AF_CLASSIFY != 1,1,0)) AS 'n_nonstandard', SUM(IF(isAddInNew = 1,1,0) ) AS 'n_total', (COUNT(AF_DEPARTMENT) - SUM(IF(isAddInNew = 1,1,0))) AS 'non_enter' FROM affairs LEFT JOIN dic_competentauth AS dept ON dept.ID = affairs.AF_DEPARTMENT WHERE dept.AREACODE = '530100000000' AND affairs.NodeType = 3 AND affairs.VALID=1 GROUP BY AF_DEPARTMENT LIMIT 5,5;