Gau*_*sal 1 sql presto amazon-athena
我有两个带有以下查询的 Athena 表:
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'
Run Code Online (Sandbox Code Playgroud)
和
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'
Run Code Online (Sandbox Code Playgroud)
我想加入他们的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
Run Code Online (Sandbox Code Playgroud)
但以上结果导致错误 mismatched input 'left' expecting {<eof>, ',', 'from', 'where', 'group', 'order', 'having', 'limit', 'union', 'except', 'intersect'}
任何 sql 中连接的语法如下所示
Select <column list>
from Table_1
left/right/inner Join Table_2
ON <join condition>
Run Code Online (Sandbox Code Playgroud)
table_1 和 table_2 可以是表或其他选择语句
你缺少 select * from,试试这个,我无法检查其他语法错误,但这是一般的想法
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12714 次 |
| 最近记录: |