我在hive中使用以下查询:
SELECT COUNT(DISTINCT INDIV_ID) FROM TABLEA
WHERE CAR1="BLUE" AND INDIV_ID
IN (SELECT DISTINCT INDIV_ID FROM TABLEA WHERE CAR2="RED" AND CAR3="WHITE")
我现在已经理解带有子句的子查询在Hive中不起作用。上面的查询的目的只是为了理解Hive的子查询中的位置的替代。
有人可以告诉我如何在Hive中编写上述查询吗?
答案 0 :(得分:0)
你可以使用CTE, 我添加了“CAR_R_W”CTE。 下面是修改后的查询。
WITH CAR_R_W
AS (
SELECT DISTINCT INDIV_ID
FROM TABLEA
WHERE CAR2 = "RED"
AND CAR3 = "WHITE"
)
SELECT COUNT(DISTINCT INDIV_ID)
FROM TABLEA
WHERE CAR1 = "BLUE"
AND INDIV_ID IN (
SELECT INDIV_ID
FROM CAR_R_W
);