我们每天都会将工程数据加载到父/子表中。为了便于用户报告,我创建了一个视图,将表格展平为单个表格布局。
我在视图中获得的记录数(As of today: 250,090
)与父表(As of today: 411,269
)中的记录数不匹配。这是视图的代码:
SEL
CAST( A.END_TIME_TEXT AS TIMESTAMP(0) ) END_TIME,
UPPER(A.OPER_NAME) OPER_NAME,
CAST( A.START_TIME_TEXT AS TIMESTAMP(0)) START_TIME,
UPPER(A.PROC_NAME) PROC_NAME ,
UPPER(A.PROC_REV_TEXT) PROC_REV_TEXT ,
A.LOC_1_NAME,
UPPER(A.LOC_1_TYPE_DESC) LOC_1_TYPE_DESC ,
UPPER(A.LOC_2_NAME) LOC_2_NAME,
UPPER(A.LOC_2_TYPE_DESC) LOC_2_TYPE_DESC,
A.LOC_3_NAME ,
UPPER(A.LOC_3_TYPE_DESC) LOC_3_TYPE_DESC,
A.LOC_4_NAME ,
UPPER(A.LOC_4_TYPE_DESC) LOC_4_TYPE_DESC ,
A.SER_NUM_TEXT ,
UPPER(A.PROD_REV_TEXT) PROD_REV_TEXT ,
UPPER(A.PROD_TYPE_DESC) PROD_TYPE_DESC,
UPPER(A.OUTCOME_TEXT ) OUTCOME_TEXT,
UPPER(A.DRIVER_PLAT_TEXT) DRIVER_PLAT_TEXT,-
CAST(A.DRIVER_REV_TEXT AS DECIMAL (1,0)) DRIVER_REV_TEXT ,
A.ENABLE_PARM_DB_COMM_TEXT ,
A.ENABLE_SFCS_COMM_TEXT ,
A.FORCE_PARM_DB_UPD_TEXT ,
B.BIST_FAIL_CODE, B.STB_CLIENT,
B.STB_CMNT, B.COMPUTER_ID,
B.CONTRACT, B.DTV_FAIL_CODE,
B.DTV_FAIL_DESC, B.TEST_END_DATE,
B.TEST_END_TIME, B.FAN_HALF_SPEED,
B.FAN_SPEED, B.HDD_ID,
B.HDD_MDL, B.HDD_POH,
B.HDD_SER, B.HDD_TEMP,
B.LINE_ID, B.MAC_ID,
B.OEM_NAME, B.STB_MDL,
B.OPERATOR_ID, B.RID,
B.RTE_ID, B.RSSI1_24GHz,
B.RSSI1_5GHz, B.RSSI2_24GHz,
B.RSSI2_5GHz, B.SCRIPT_ID,
B.SCRIPT_VER, B.SERVER_DRIVE_VER,
B.SITE_ID, B.SLOT_ID,
B.SER_NUM, B.SQ1_24GHz,
B.SQ1_5GHz, B.SQ2_24GHz,
B.SQ2_5GHz, B.SSID_24GHz,
B.SSID_5GHz, B.TEST_START_DATE,
B.TEST_START_TIME, B.SWIN,
B.SWOUT, B.TEST_RESULT,
B.TEST_TIME, B.TIME_TO_FAIL,
B.STB_TYPE, B.WORK_CENTER_ID
FROM AUTO_REPR_PAR A,
(
SELECT TEST_SEQ_NUM,
MAX(CASE WHEN PARM_NAME = 'BISTFAILCODE' THEN PARM_VAL END) BIST_FAIL_CODE,
MAX(CASE WHEN PARM_NAME = 'Client' THEN UPPER(PARM_VAL) END) STB_CLIENT,
MAX(CASE WHEN PARM_NAME = 'Comment' THEN UPPER(PARM_VAL) END) STB_CMNT,
MAX(CASE WHEN PARM_NAME = 'ComputerID' THEN UPPER(PARM_VAL) END) COMPUTER_ID,
MAX(CASE WHEN PARM_NAME = 'Contract' THEN UPPER(PARM_VAL) END) CONTRACT,
MAX(CASE WHEN PARM_NAME = 'DTVFAILCODE' THEN PARM_VAL END) DTV_FAIL_CODE,
MAX(CASE WHEN PARM_NAME = 'DTVFAILDESC' THEN PARM_VAL END) DTV_FAIL_DESC,
MAX(CASE WHEN PARM_NAME = 'EndDate' THEN CAST(PARM_VAL AS DATE FORMAT 'YYYYMMDD') END) TEST_END_DATE,
MAX(CASE WHEN PARM_NAME = 'EndTime' THEN (PARM_VAL (TIME, FORMAT 'HHMISS')) END) TEST_END_TIME,
MAX(CASE WHEN PARM_NAME = 'FANHalfSpeed' THEN PARM_VAL END) FAN_HALF_SPEED,
MAX(CASE WHEN PARM_NAME = 'FANSpeed' THEN PARM_VAL END) FAN_SPEED,
MAX(CASE WHEN PARM_NAME = 'HDDID' THEN UPPER(PARM_VAL) END) HDD_ID,
MAX(CASE WHEN PARM_NAME = 'HDDModel' THEN UPPER(PARM_VAL) END) HDD_MDL,
MAX(CASE WHEN PARM_NAME = 'HDDPOH' THEN PARM_VAL END) HDD_POH,
MAX(CASE WHEN PARM_NAME = 'HDDSerial' THEN PARM_VAL END) HDD_SER,
MAX(CASE WHEN PARM_NAME = 'HDDTEMP' THEN PARM_VAL END)HDD_TEMP,
MAX(CASE WHEN PARM_NAME = 'LineID' THEN PARM_VAL END) LINE_ID,
MAX(CASE WHEN PARM_NAME = 'MACID' THEN PARM_VAL END) MAC_ID,
MAX(CASE WHEN PARM_NAME = 'Manufacturer' THEN UPPER(PARM_VAL) END)OEM_NAME,
MAX(CASE WHEN PARM_NAME = 'Model' THEN UPPER(PARM_VAL) END) STB_MDL,
MAX(CASE WHEN PARM_NAME = 'OperatorID' THEN UPPER(PARM_VAL) END) OPERATOR_ID,
MAX(CASE WHEN PARM_NAME = 'RID' THEN PARM_VAL END)RID,
MAX(CASE WHEN PARM_NAME = 'RouteID' THEN UPPER(PARM_VAL) END)RTE_ID,
MAX(CASE WHEN PARM_NAME = 'RSSI1_24GHz' THEN PARM_VAL END)RSSI1_24GHz,
MAX(CASE WHEN PARM_NAME = 'RSSI1_5GHz' THEN PARM_VAL END) RSSI1_5GHz,
MAX(CASE WHEN PARM_NAME = 'RSSI2_24GHz' THEN PARM_VAL END) RSSI2_24GHz,
MAX(CASE WHEN PARM_NAME = 'RSSI2_5GHz' THEN PARM_VAL END) RSSI2_5GHz,
MAX(CASE WHEN PARM_NAME = 'ScriptID' THEN PARM_VAL END)SCRIPT_ID,
MAX(CASE WHEN PARM_NAME = 'ScriptVer' THEN PARM_VAL END)SCRIPT_VER,
MAX(CASE WHEN PARM_NAME = 'ServerDriveVer' THEN PARM_VAL END)SERVER_DRIVE_VER,
MAX(CASE WHEN PARM_NAME = 'SiteID' THEN UPPER(PARM_VAL) END)SITE_ID,
MAX(CASE WHEN PARM_NAME = 'SlotID' THEN PARM_VAL END) SLOT_ID,
MAX(CASE WHEN PARM_NAME = 'SN' THEN PARM_VAL END) SER_NUM,
MAX(CASE WHEN PARM_NAME = 'SQ1_24GHz' THEN PARM_VAL END) SQ1_24GHz,
MAX(CASE WHEN PARM_NAME = 'SQ1_5GHz' THEN PARM_VAL END) SQ1_5GHz,
MAX(CASE WHEN PARM_NAME = 'SQ2_24GHz' THEN PARM_VAL END) SQ2_24GHz,
MAX(CASE WHEN PARM_NAME = 'SQ2_5GHz' THEN PARM_VAL END) SQ2_5GHz,
MAX(CASE WHEN PARM_NAME = 'SSID_24GHz' THEN PARM_VAL END)SSID_24GHz,
MAX(CASE WHEN PARM_NAME = 'SSID_5GHz' THEN PARM_VAL END) SSID_5GHz,
MAX(CASE WHEN PARM_NAME = 'StartDate' THEN CAST(PARM_VAL AS DATE FORMAT 'YYYYMMDD') END) TEST_START_DATE,
MAX(CASE WHEN PARM_NAME = 'StartTime' THEN (PARM_VAL (TIME, FORMAT 'HHMISS')) END) TEST_START_TIME,
MAX(CASE WHEN PARM_NAME = 'SWin' THEN PARM_VAL END) SWIN,
MAX(CASE WHEN PARM_NAME = 'SWout' THEN PARM_VAL END) SWOUT,
MAX(CASE WHEN PARM_NAME = 'TestResult' THEN UPPER(PARM_VAL) END) TEST_RESULT,
MAX(CASE WHEN PARM_NAME = 'TestTime' THEN PARM_VAL END) TEST_TIME,
MAX(CASE WHEN PARM_NAME = 'TimetoFail' THEN PARM_VAL END) TIME_TO_FAIL,
MAX(CASE WHEN PARM_NAME = 'TYPE' THEN UPPER(PARM_VAL) END) STB_TYPE,
MAX(CASE WHEN PARM_NAME = 'WorkCenterID' THEN UPPER(PARM_VAL) END) WORK_CENTER_ID
FROM
(
SELECT TEST_SEQ_NUM,PARM_NAME,PARM_VAL,
ROW_NUMBER() OVER(PARTITION BY TEST_SEQ_NUM ORDER BY TEST_SEQ_NUM) SEQ
FROM AUTO_REPR_CHLD
) D
GROUP BY TEST_SEQ_NUM
)
B,
RMA_MFR_MDL_PAR_XREF C
WHERE A.TEST_SEQ_NUM=B.TEST_SEQ_NUM
AND A.LOC_1_NAME=B.SITE_ID
AND A.PROD_TYPE_DESC=C.MFR_SKU_CODE AND C.IRD_FLAG='Y'
这是从父表中获取行数的SQL
SELECT LOC_1_NAME,SUBSTR(END_TIME_TEXT,1,10), COUNT(*) FROM DDWP_V.AUTO_REPR_PAR GROUP BY 1,2
我删除了从子表中选择的partition子句,没有更改。我错过了什么?
答案 0 :(得分:0)
问题在于内部连接而不是左外连接。固定的。
SEL
CAST( A.END_TIME_TEXT AS TIMESTAMP(0) ) END_TIME,
UPPER(A.OPER_NAME) OPER_NAME,
...B.TIME_TO_FAIL,
B.STB_TYPE,
B.WORK_CENTER_ID
FROM AUTO_REPR_PAR A
LEFT OUTER JOIN
(
SELECT TEST_SEQ_NUM,
MAX(CASE WHEN PARM_NAME = 'BISTFAILCODE' THEN PARM_VAL END) BIST_FAIL_CODE,
...
MAX(CASE WHEN PARM_NAME = 'MANUFACTURER' THEN UPPER(PARM_VAL) END)OEM_NAME,
MAX(CASE WHEN PARM_NAME = 'WORKCENTERID' THEN UPPER(PARM_VAL) END) WORK_CENTER_ID
FROM
(
SELECT TEST_SEQ_NUM,PARM_NAME,PARM_VAL
FROM AUTO_REPR_CHLD
) D
GROUP BY TEST_SEQ_NUM
)
B
ON
A.TEST_SEQ_NUM=B.TEST_SEQ_NUM
AND A.LOC_1_NAME=B.SITE_ID
LEFT OUTER JOIN RMA_MFR_MDL_PAR_XREF C
ON A.PROD_TYPE_DESC=C.MFR_SKU_CODE AND C.IRD_FLAG='Y'
WHERE
END_TIME IS NOT NULL
感谢大家的帮助。