2017-05-31 49 views
-1

這是在Big Query中基於級聯不等式的約束SQL。 date1用作中間參數。基於其他SELECT參數的不相等基礎SQL

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

環路版本:在其他人尋找的情況下

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

回答

0

一種特殊情況的解決方案。 JOIN可用於對齊兩個表,如果它們共享相同的ID。

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