在BigQuery,标准SQL中,如何在几个表上使用_TABLE_SUFFIX?见例:
select *
from `table1.*` t1
left join `table2.*` t2 on t1.lel=t2.lel
where _TABLE_SUFFIX between '2017-01-01' and '2017-01-02' <--- this can't be used
我是否有义务创建table2的子查询,并首先应用table_suffix?
答案 0 :(得分:2)
在您的查询中_TABLE_SUFFIX
含糊不清,因为BigQuery无法判断它是来自t1还是t2。您可以使用显式前缀t1.
或t2.
消除歧义,即
select *
from `table1.*` t1
left join `table2.*` t2 on t1.lel=t2.lel
where t1._TABLE_SUFFIX between '2017-01-01' and '2017-01-02'
答案 1 :(得分:0)
您还可以添加另一个table_suffix条件,例如,
select *
from `table1.*` t1
left join `table2.*` t2 on t1.lel=t2.lel
where t1._TABLE_SUFFIX between '2017-01-01' and '2017-01-02'
and t2._TABLE_SUFFIX between '2017-01-01' and '2017-01-02'
Mosha答案之间的区别在于,他的查询将扫描左联接中的所有表(成本较高且绩效较低),在我发送的示例中,它将仅扫描满足表后缀条件的表,
该方法的唯一问题是bigquery像它的内部联接一样运行它,而不是离开它,例如,如果您要添加条件并且t2.tel为null,则不会收到0个结果