基于其他SELECT参数的不等基SQL

时间:2017-05-31 13:49:13

标签: google-bigquery

这是在Big Query中基于级联不等式的约束SQL。 date1用作中间参数。

Select  id, date, date1
 From   table1
 Where  date > date1  
        AND date1 in ( select dateref from table2)

In Loop版本:

For all date1 in (select dateref from table2) :
   select id, date, date1
   from table1 
   where date > date1

1 个答案:

答案 0 :(得分:0)

一个特殊情况解决方案,以防其他人寻找。 如果两个表共享相同的id,则JOIN可用于对齐这两个表。

select  same_id, date1,  dateref 

from ( 
   select   g1.same_id,  date1,  g2.dateref  
   from   `log2*`   as g1
   JOIN
      (  
        select  dateref,
          from `log1*`
          WHERE _TABLE_SUFFIX BETWEEN '20170101' AND '20170630'
      )   as g2
      ON   g1.same_id = g2.same_id  


where
     _TABLE_SUFFIX BETWEEN '20170101' AND '20170630'
)
where 
      date1 > dateref