连接查询与蜂巢中的数值比较

时间:2019-02-05 04:53:54

标签: hive

我在TEMP.total_labor_hours> =(.95 * M.MAX_HOURS)下的以下配置单元查询中遇到问题,请建议我如何重写它

 `SELECT BAC,COUNTRY_CD,COUNT(*)
FROM DL_EDGE_LRF_GWM_13929_BASE_GWMCNPD_COGNOSDBO.RISK_IND_CALC_TEMP AS TEMP
INNER JOIN 
(SELECT LABOR_OPERATION_KEY,LABOR_OPERATION_CD,LABOR_OPERATION_CD_EN,MAKE,MODEL,MAX_HOURS
  FROM DL_EDGE_LRF_GWM_13929_BASE_GWMCNPD_COGNOSDBO.RISK_IND_03_TMP1) M
ON M.LABOR_OPERATION_KEY = TEMP.LABOR_OPERATION_KEY
AND TEMP.UMF_XREF_FINC_MKTG_DIV = M.MAKE
AND TEMP.UMF_XREF_FINC_BRAND = M.MODEL
AND TEMP.total_labor_hours >= (.95 * M.MAX_HOURS)
WHERE TEMP.transaction_type_key IN ('16','17') AND TEMP.PROCESS_STATUS_key = '11'
GROUP BY BAC,COUNTRY_CD`

1 个答案:

答案 0 :(得分:0)

配置单元中不能有非等式连接。

使用where子句重写查询-

 `SELECT BAC,COUNTRY_CD,COUNT(*)
FROM DL_EDGE_LRF_GWM_13929_BASE_GWMCNPD_COGNOSDBO.RISK_IND_CALC_TEMP AS TEMP , DL_EDGE_LRF_GWM_13929_BASE_GWMCNPD_COGNOSDBO.RISK_IND_03_TMP1 M
where M.LABOR_OPERATION_KEY = TEMP.LABOR_OPERATION_KEY
AND TEMP.UMF_XREF_FINC_MKTG_DIV = M.MAKE
AND TEMP.UMF_XREF_FINC_BRAND = M.MODEL
AND TEMP.total_labor_hours >= (.95 * M.MAX_HOURS) AND TEMP.transaction_type_key IN ('16','17') AND TEMP.PROCESS_STATUS_key = '11'
GROUP BY BAC,COUNTRY_CD`;

以上查询将导致交叉联接,然后根据条件条件过滤数据。 如果花费更多时间,则更改连接条件,下面将是查询-

 `SELECT BAC,COUNTRY_CD,COUNT(*)
FROM DL_EDGE_LRF_GWM_13929_BASE_GWMCNPD_COGNOSDBO.RISK_IND_CALC_TEMP AS TEMP
LEFT OUTER JOIN 
(SELECT LABOR_OPERATION_KEY,LABOR_OPERATION_CD,LABOR_OPERATION_CD_EN,MAKE,MODEL,MAX_HOURS
  FROM DL_EDGE_LRF_GWM_13929_BASE_GWMCNPD_COGNOSDBO.RISK_IND_03_TMP1) M
ON M.LABOR_OPERATION_KEY = TEMP.LABOR_OPERATION_KEY
AND TEMP.UMF_XREF_FINC_MKTG_DIV = M.MAKE
AND TEMP.UMF_XREF_FINC_BRAND = M.MODEL
where M.MAX_HOURS IS NOT NULL AND TEMP.total_labor_hours >= (.95 * M.MAX_HOURS)
TEMP.transaction_type_key IN ('16','17') AND TEMP.PROCESS_STATUS_key = '11'
GROUP BY BAC,COUNTRY_CD`