0
我正在將統計數據從MySQL切換到Amazon DynamoDB和Elastic MapReduce。Hive多個子查詢和組由
我有查詢波紋管與MySQL的工作,我有蜂巢上的同一個表,並需要在MySQL(last_week,last_month和last_year的產品視圖)相同的結果。
SELECT product_id,
SELECT COUNT(product_id) from dev_product_views_hive as P2 where P2.product_id=P.product_id and created >= DATE_SUB(NOW(), INTERVAL 1 WEEK) as weekly,
SELECT count(product_id) from dev_product_views_hive as P3 where P3.product_id=P.product_id and created >= DATE_SUB(NOW(), INTERVAL 1 MONTH) as monthly,
SELECT count(product_id) from dev_product_views_hive as P4 where P4.product_id=P.product_id and created >= DATE_SUB(NOW(), INTERVAL 1 YEAR) as yearly
from dev_product_views_hive as P group by product_id;
我想通了,如何獲得具有蜂巢例如結果上個月:
SELECT product_id, COUNT(product_id) as views from dev_product_views_hive WHERE created >= UNIX_TIMESTAMP(CONCAT(DATE_SUB(FROM_UNIXTIME(UNIX_TIMESTAMP()), 31)," ","00:00:00")) GROUP BY product_id;
,但我需要分組結果就像我得到與MySQL:
product_id views_last_week views_last_month views_last_year
2 564 2460 29967
4 980 3986 54982
是否有可能與蜂巢做到這一點?
謝謝你在前進,
阿米爾
你試過了嗎? – 2013-03-04 12:39:26
是的,總是得到解析錯誤,我不知道如何在hiveql中正確編寫這個MySQL子查詢。 Hiveql不像MySQL那樣的語法。 – trkich 2013-03-04 14:07:25
hive ql僅支持子句 – 2013-03-04 17:25:16