Impala SQL在t1和t2上保持联接

时间:2018-05-29 01:03:27

标签: sql cloudera impala

我在这里加入了一个问题,特别是on x = y 在SQL Impala中,有人可以帮助我了解它是如何工作的。 SUBSTR(cast(t1.employee_number as string), 3,10) as short_employee_number工作正常,我测试了,但是当我构建这个左连接时,我不明白最终应该在x = y上 我试过了

SUBSTR(cast(t1.employee_number as string), 3,10) =  t2.short_staff_number
t1.short_employee_number =  t2.short_staff_number
short_employee_number=  t2.short_staff_number

没有一个奏效。

有什么问题?

 SELECT DISTINCT
    SUBSTR(cast(t1.employee_number as string), 3,10) as short_employee_number, 
    t1.begin_date_it0001,
    t1.end_date_it0001,
    t1.cost_center
    t1.position,
    t2.local_time_createddate,
    t2.area,
    t2. unit, 
    t2.short_staff_number, 
    t2.alias, 
    t2.email

    FROM dataone  as t1 
    LEFT JOIN datatwo as  t2 
    ON 
    short_employee_number  = t2.short_staff_number ;

1 个答案:

答案 0 :(得分:0)

试试这个

您无法使用SELECT FIELDS上的FROM,而只能使用ORDER BY

SELECT DISTINCT
    SUBSTR(cast(t1.employee_number as string), 3,10) as short_employee_number, 
    t1.begin_date_it0001,
    t1.end_date_it0001,
    t1.cost_center
    t1.position,
    t2.local_time_createddate,
    t2.area,
    t2. unit, 
    t2.short_staff_number, 
    t2.alias, 
    t2.email

    FROM dataone  as t1 
    LEFT JOIN datatwo as  t2 
    ON 
     SUBSTR(cast(t1.employee_number as string), 3,10)  = t2.short_staff_number ;