我正在寻找一些帮助,将非equi连接查询转换为仅支持equi连接查询的hive。
我尝试过这样做,并且很高兴知道如果我把它们弄好了,请让我知道我的错误以及实现同样的正确方法。
A)
SELECT
a.time_p,
count(distinct a.consumerid)
from tableA a
join tableB
on a.consumerid = tableB.consumerid
and tableB.time_p != a.time_p
group by a.time_p
我试过了::
SELECT time_p as period, count(distinct consumerid) as count
FROM(
SELECT
a.time_p,
a.consumerid,
CASE
WHEN tableB.time_p != a.time_p THEN 1
ELSE null END as testcase
from tableA a
join tableB
on a.consumerid = tableB.consumerid
)t WHERE testcase is not null
group by time_p
由于
答案 0 :(得分:2)
你可以有不平等条件 - 只是不作为连接条件:
SELECT a.time_p,count(distinct a.consumerid)
from tableA a
join tableB b
ON a.consumerid = b.consumerid
WHERE b.time_p != a.time_p
group by a.time_p;
加入后将应用WHERE
条件。