SELECT BB.单位, Sum(BB.检查小号数量) AS 小号, Sum(BB.检查小班数量) AS 小班
FROM [SELECT 单位, count(检查小号) AS 检查小号数量,0 AS 检查小班数量
FROM [SELECT DISTINCT 表1.单位, 表1.检查小号
FROM 表1]. AS AA
GROUP BY 单位
union SELECT 单位,0 AS 检查小号数量, count(检查小班) AS 检查小班数量
FROM [SELECT DISTINCT 表1.单位, 表1.检查小班
FROM 表1]. AS AA
GROUP BY 单位]. AS BB
GROUP BY BB.单位;