2017-02-17 1 views
0

이러한 쿼리는 임팔라에서 실행됩니다.임팔라 - 존재 (하위 쿼리) 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 이 필드 1에 해당하는 날짜 .concrete_date '는 두 번째 쿼리는 확인을 예상 행을 반환

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