我想将三个查询的结果添加到一个查询中:
select file_name,count(distinct uniq_key) FILE_LOAD_REC_COUNT from STG_STRR_CTDI_CMTX2_TEMP1 group by file_name;
select file_name,count(distinct uniq_key) ERR_REC_COUNT_M from STG_STRR_CTDI_ERR_DESC1 where err_desc in ('DUPLICATE RECORD','MISSING MANDATORY DEVICE DETAILS') group by file_name;
select file_name,count(distinct uniq_key) ERR_REC_COUNT_O from STG_STRR_CTDI_ERR_DESC1 where err_desc not in ('DUPLICATE RECORD','MISSING MANDATORY DEVICE DETAILS') group by file_name;
我想要以下格式的结果:
FILE_NAME|FILE_LOAD_REC_COUNT|ERR_REC_COUNT_M|ERR_REC_COUNT_O
ABC.json|10|10|20|29
我该怎么做?
答案 0 :(得分:0)
SELECT文件名, COUNT(DISTINCT uniq_key)FILE_LOAD_REC_COUNT, 0 ERR_REC_COUNT_M, 0 ERR_REC_COUNT_O 来自STG_STRR_CTDI_CMTX2_TEMP1 GROUP BY file_name 联合所有
SELECT文件名, 0个FILE_LOAD_REC_COUNT个, COUNT(区分大小写) 当err_desc IN('DUPLICATE RECORD', “缺少强制性设备的详细信息”)然后uniq_key END)ERR_REC_COUNT_M, COUNT(区分大小写) 当err_desc NOT IN(“重复记录”时, “缺少强制性设备的详细信息”)然后uniq_key END)ERR_REC_COUNT_O 来自STG_STRR_CTDI_ERR_DESC1 GROUP BY文件名
SELECT文件名, 总和(FILE_LOAD_REC_COUNT)FILE_LOAD_REC_COUNT, SUM(ERR_REC_COUNT_M)ERR_REC_COUNT_M, 总和(ERR_REC_COUNT_O)ERR_REC_COUNT_O 从 (
SELECT文件名, COUNT(DISTINCT uniq_key)FILE_LOAD_REC_COUNT, 0 ERR_REC_COUNT_M, 0 ERR_REC_COUNT_O 来自STG_STRR_CTDI_CMTX2_TEMP1 GROUP BY file_name 联合所有
SELECT文件名, 0个FILE_LOAD_REC_COUNT个, COUNT(区分大小写) 当err_desc IN('DUPLICATE RECORD', “缺少强制性设备的详细信息”)然后uniq_key END)ERR_REC_COUNT_M, COUNT(区分大小写) 当err_desc NOT IN(“重复记录”时, “缺少强制性设备的详细信息”)然后uniq_key END)ERR_REC_COUNT_O 来自STG_STRR_CTDI_ERR_DESC1 GROUP BY file_name ) GROUP BY file_name;