SELECT
CASE WHEN GROUPING( [劳动保护监督_主表].[单位]) = 1 THEN '合计' ELSE [劳动保护监督_主表].[单位] END AS 本报表.[劳动保护统计_明细表].[单位名称]xFN,
CASE WHEN GROUPING( [劳动保护监督_主表].[部门名称]) = 1 AND GROUPING( [劳动保护监督_主表].[单位]) = 0 THEN '小计' ELSE [劳动保护监督_主表].[部门名称] END AS 本报表.[劳动保护统计_明细表].[检查部门]xFN,
YEAR([劳动保护监督_明细表].[检查日期]) AS 本报表.[劳动保护统计_明细表].[检查年份]xFN,
[劳动保护监督_主表].[检查数] As 本报表.[劳动保护统计_明细表].[检查数量]xFN,
[劳动保护监督_主表].[已整改] As 本报表.[劳动保护统计_明细表].[整改数量]xFN
FROM [劳动保护监督_主表] LEFT JOIN [劳动保护监督_明细表] On [劳动保护监督_主表].[报表ID] = [劳动保护监督_明细表].[报表ID]
慕表来