SELECT DIM_MONTH, '住院单据主表', 'COMM.APPLY_SHEET' as BUS_TABLE, 'EXTBI.RESI_CLINIC_BILL_MASTER' as HDC_TABLE, MAX(BUS_DATA_CNT) AS BUS_DATA_CNT,MAX(HDC_DATA_CNT) AS HDC_DATA_CNT, 2 as TABLE_TYPE FROM ( SELECT TRUNC(APPLY_TIME,'MM') AS DIM_MONTH, COUNT(1) AS BUS_DATA_CNT, 0 AS HDC_DATA_CNT FROM COMM.APPLY_SHEET@ZYHIS4 WHERE APPLY_TIME >= TO_DATE(20190101,'YYYYMMDD') AND APPLY_TIME < ADD_MONTHS(TO_DATE(20200201,'YYYYMMDD'),1) AND VISIT_NUMBER > 0 GROUP BY TRUNC(APPLY_TIME,'MM') UNION ALL SELECT TRUNC(APPLY_TIME,'MM') AS DIM_MONTH, 0 AS BUS_DATA_CNT, COUNT(1) AS HDC_DATA_CNT FROM EXTBI.RESI_CLINIC_BILL_MASTER@ZYHDC WHERE APPLY_TIME >= TO_DATE(20190101,'YYYYMMDD') AND APPLY_TIME < ADD_MONTHS(TO_DATE(20200201,'YYYYMMDD'),1) GROUP BY TRUNC(APPLY_TIME,'MM') ) GROUP BY DIM_MONTH