2017-02-17 27 views
0

這些查詢在Impala中運行。Impala - 存在(子查詢)VS 0 <(選擇計數(*)...)

兩個類似的查詢應該有相同的結果,但有兩個不同的結果。

此查詢獲取所有預期(約130在我的實際情況)的結果

select field1, field2, concrete_date 
from tableA a 
where exists(select * 
    from tableB b 
    where b.field1 = a.field1 
     and b.concrete_date > (a.concrete_date + interval -5 minutes) 
     and b.concrete_date < (a.concrete_date + interval 5 minutes) 
) 

此查詢返回的結果(約10在我的實際情況)的小部分

select field1, field2, concrete_date 
from tableA a 
where 0 < (select count(*) 
    from tableB b 
    where b.field1 = a.field1 
     and b.concrete_date > (a.concrete_date + interval -5 minutes) 
     and b.concrete_date < (a.concrete_date + interval 5 minutes) 
) 

在哪裏是什麼區別?我看不到它...

在我的測試中,如果我從我的第一個查詢中獲取field1的一個具體值(但不會出現在第二個查詢結果中)並強制子查詢更改'a .concrete_date」與對應於該字段1日起,第二個查詢返回預期的行確定

select field1, field2, concrete_date 
from tableA a 
where 0 < (select count(*) 
    from tableB b 
    where b.field1 = 'XXXXX' 
     and b.concrete_date > ('2017-01-01 00:00:00' + interval -5 minutes) 
     and b.concrete_date < ('2017-01-01 00:00:00' + interval 5 minutes) 
) 

回答

1

其中b.field1 = a.field2
其中b.field1 = a.field1

有區別。

+0

這是查詢示例中的錯誤,而不是真正的查詢。 – Kzas