0
我正在使用Hive並希望將Query_1與Query_2合併。兩者都是分開工作:
--> Query_1
SELECT DISTINCT
table_a.number,
table_a.country,
table_a.brand
FROM db_y.table_b,db_x.table_a
WHERE table_a.date = '20160718'
AND CAST (table_a.brand as DOUBLE) IS NOT NULL
AND table_a.number = table_b.number
AND table_a.country = table_b.country
AND table_a.brand = table_b.brand
991 413 7040482
991 413 7040484
991 413 7040486
--> Query_2
SELECT DISTINCT
table_a.number,
table_a.country,
table_a.brand
FROM db_x.table_a,db_x.table_c
WHERE table_a.date = '20160719'
AND table_a.brand = substring(table_c.brand,2,7)
AND table_a.country = substring(table_c.country,2,3)
AND table_a.number = substring(table_c.number,2,3)
907 298 0004130 --> found in table_b
907 298 0004138
907 410 7024257
問題:
下面,合併後的查詢Query_3不起作用,爲什麼呢?
--> Query_3
SELECT DISTINCT
table_a.number,
table_a.country,
table_a.brand
FROM db_y.table_b,db_x.table_a,db_x.table_c
WHERE table_a.date = '20160718'
AND table_a.number = table_b.number
AND table_a.country = table_b.country
AND table_a.brand = table_b.brand
AND table_b.brand = substring(table_c.brand,2,7)
AND table_b.country = substring(table_c.country,2,3)
AND table_b.number = substring(table_c.number,2,3);
這裏是Query_3的替代查詢工作:
SELECT DISTINCT
table_a.number,
table_a.country,
table_a.brand
FROM db_x.table_a,(SELECT DISTINCT
table_b.number,
table_b.country,
table_b.brand
FROM db_y.table_b,db_x.table_c
WHERE table_b.brand = substring(table_c.brand,2,7)
AND table_b.country = substring(table_c.country,2,3)
AND table_b.number = substring(table_c.number,2,3)) subq
WHERE table_a.date = '20160718'
AND table_a.number = subq.number
AND table_a.country = subq.country
AND table_a.brand = subq.brand;
但我真的想了解,爲什麼Query_3是錯誤的。
信息:
- 在我的電腦,它會阻止96%的減少步
- 在我朋友的一個(比我更好的容量),則返回0的結果(雖然我們期待結果)
謝謝。
'MySQL'或'hive'?你可能有不同的數據類型,在最後三個條件中改爲'table_a'而不是'table_b'。 – dnoeth
修復您的查詢以使用明確的'JOIN'語法。如果你這樣做,你可能會發現一個問題。 。 。而且它至少會使讀者更清楚地閱讀它。 –
@dnoeth:這裏使用了Hive。我改變它,它現在運行在我的電腦上,但我得到0結果。 –