impala-exists(子查询)vs 0< (选择计数(*)…)

ymzxtsji  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(281)

这些查询在impala中运行。
两个相似的查询应该有相同的结果,但有两个不同的结果。
这个查询得到了所有预期的结果(在我的实际案例中大约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的一个具体值(但它没有出现在第二个查询结果中),并强制子查询用对应于该field1的日期更改“a.concrete\u date”,则第二个查询返回预期的行ok

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) 
)
oiopk7p5

oiopk7p51#

其中b.field1=a.field2
其中b.field1=a.field1
有区别。

相关问题