我有两个带有以下查询的雅典娜表:
select
date,
uid,
logged_hrs,
extract(hour from start_time) as hour
from schema.table1
where building = 'MKE'
and pt_date between date '2019-01-01' and date '2019-01-09'
和
select
associate_uid as uid,
date(substr(fcdate_utc, 1, 10)) as pt_date,
learning_curve_level
from tenure.learningcurve
where warehouse_id = 'MKE'
and date(substr(fcdate_utc, 1, 10)) between date '2019-01-01' and date '2019-01-09'
我想在uid
和pt_date
上加入他们。我怎样才能做到这一点?
我尝试过:
select (select
date,
uid,
logged_hrs,
extract(hour from start_time) as hour
from schema.table1
where building = 'MKE'
and pt_date between date '2019-01-01' and date '2019-01-09') as a
left join (select
associate_uid as uid,
date(substr(fcdate_utc, 1, 10)) as pt_date,
learning_curve_level
from tenure.learningcurve
where warehouse_id = 'MKE'
and date(substr(fcdate_utc, 1, 10)) between date '2019-01-01' and date '2019-01-09'
) as b
on a.uid=b.uid and a.pt_date = b.pt_date
但是以上情况导致错误mismatched input 'left' expecting {<eof>, ',', 'from', 'where', 'group', 'order', 'having', 'limit', 'union', 'except', 'intersect'}
答案 0 :(得分:2)
在任何sql中联接的语法如下所示
Select <column list>
from Table_1
left/right/inner Join Table_2
ON <join condition>
table_1和table_2可以是表或其他选择语句
您缺少选择*, 试试这个,我无法检查其他语法错误,但这是一般想法
select a.*, b.*
from (select date,
uid,
logged_hrs,
extract(hour from start_time) as hour
from schema.table1
where building = 'MKE'
and pt_date between date '2019-01-01' and date '2019-01-09'
) as a
left join
(select associate_uid as uid,
date(substr(fcdate_utc, 1, 10)) as pt_date,
learning_curve_level
from tenure.learningcurve
where warehouse_id = 'MKE'
and date(substr(fcdate_utc, 1, 10)) between date '2019-01-01' and date '2019-01-09'
) as b
on a.uid=b.uid and a.pt_date = b.pt_date