Both left and right aliases encountered in Hive JOIN; without any inequality clause

前端 未结 3 1041
鱼传尺愫
鱼传尺愫 2021-02-13 20:37

I am using following query:

Select
   S.MDSE_ITEM_I,
   S.CO_LOC_I,
   MAX(S.SLS_D) as MAX_SLS_D,
   MIN(S.SLS_D) as MIN_SLS_D,
   sum(S.SLS_UNIT_Q) as SLS_UNIT_         


        
相关标签:
3条回答
  • 2021-02-13 20:58

    Try to move the inequality condition from on clause to the where condition .

    Select S.MDSE_ITEM_I,S.CO_LOC_I,
           MAX(S.SLS_D) as MAX_SLS_D,
           MIN(S.SLS_D) as MIN_SLS_D,
           sum(S.SLS_UNIT_Q) as SLS_UNIT_Q,
           MIN(PRSMN_VAL_STRT_D) as PRSMN_VAL_STRT_D,
           MIN(PRSMN_VAL_END_D) as PRSMN_VAL_END_D,
           MIN(RC.FRST_RCPT_D) as FRST_RCPT_D,
           MIN(RC.CURR_ACTV_FRST_OH_D) as CURR_ACTV_FRST_OH_D,
           MIN(H.GREG_D) as  OH_GREG_D
    from eefe_lstr4.SLS_TBL as S
             left outer join eefe_lstr4.PRS_TBL P on S.MDSE_ITEM_I = P.MDSE_ITEM_I and S.CO_LOC_I = P.CO_LOC_I 
             left outer join eefe_lstr4.OROW_RCPT RC on RC.MDSE_ITEM_I =S.MDSE_ITEM_I and RC.CO_LOC_I =  S.CO_LOC_I
             left outer join eefe_lstr4.OH H on H.MDSE_ITEM_I =S.MDSE_ITEM_I and H.CO_LOC_I = S.CO_LOC_I
    where(S.SLS_D between PRSMN_VAL_STRT_D and PRSMN_VAL_END_D)
    group by S.MDSE_ITEM_I, S.CO_LOC_I;
    
    0 讨论(0)
  • 2021-02-13 21:01

    you're right. The where clause should include nulls where records could get dropped:

    where (PRSMN_VAL_STRT_D IS NULL) or (S.SLS_D between PRSMN_VAL_STRT_D and PRSMN_VAL_END_D)

    0 讨论(0)
  • 2021-02-13 21:15

    The problem I see with this approach is that, because there is a left outer join, that means we want to have all registers from left table just once, if we move the conditions to where clause, then those registeres where right table columns are null are lost.

    0 讨论(0)
提交回复
热议问题