BigQuery 根据条件连接表
BigQuery Join tables based on condition
Table 否 1:
Table 否 2:
结果
I have 2 Table :
In table 1 column Name is unique identifier and also in Table 2 column Name is unique identifier
Based on Table 2 ,column : Name I want to get data from Table 1 then I want to map the column tags on which date it is applied in Table2 column Date.
As in table 2 , column : name , value :ghi , Date : 2/4/2022 tag was applied but in table 1 we have a cost for 2/1/2022 and 2/4/2022. so in result i will say on 2/1/2022 (no set) and after we give its value.
因此您可以使用如下查询
select
t1.date,
t1.Name,
t1.cost,
IFNULL(t2.tags,'(not set)')
from table1 t1 left outer join
table2 t2 on t1.name=t2.name and t1.date>=t2.date
Table 否 1:
Table 否 2:
结果
I have 2 Table :
In table 1 column Name is unique identifier and also in Table 2 column Name is unique identifier
Based on Table 2 ,column : Name I want to get data from Table 1 then I want to map the column tags on which date it is applied in Table2 column Date.
As in table 2 , column : name , value :ghi , Date : 2/4/2022 tag was applied but in table 1 we have a cost for 2/1/2022 and 2/4/2022. so in result i will say on 2/1/2022 (no set) and after we give its value.
因此您可以使用如下查询
select
t1.date,
t1.Name,
t1.cost,
IFNULL(t2.tags,'(not set)')
from table1 t1 left outer join
table2 t2 on t1.name=t2.name and t1.date>=t2.date