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结果。 –