2015-10-09 50 views
-1

我是一個初級使用HiveQL,我試圖寫一個更快,更高效的查詢,但有麻煩。有人可以幫我重寫這個查詢嗎?您也可以提供任何提示以改進我的查詢的提示。難以編寫子查詢

select "AUDIOONLYtopctrbyweek37Q32015", weekofyear(day),op.order_id,oppty_amount, mv.order_start_date, mv.order_end_date, count(distinct rdz.listener_id) as listeners, sum(impressions) , sum(clicks), (sum(clicks)/sum(impressions)) as ctr, sum(oline_net_amount) 
from ROLLUP_PST rdz 
join dfp2ss mv on (rdz.order_id = mv.dfp_order_id) 
join oppty_order_oline op on (mv.order_id = op.order_id) 
where day >= '2015-09-07' 
and day <= '2015-09-13' 
and creative_size in ('2000x132','134x1285','2000x114') 
group by "AUDIOONLYtopctrbyweek37Q32015", weekofyear(day),op.order_id,oppty_amount, mv.order_start_date, mv.order_end_date 

爲了通過CTR降序 極限150;

+0

此問題是離題。如果您有需要改進的工作代碼,請考慮將其發佈到http://codereview.stackexchange.com/上。 – gobrewers14

回答

0

請嘗試下面的修改後的查詢。它會爲你工作。

select "AUDIOONLYtopctrbyweek37Q32015",week_of_year,order_id,oppty_amount,order_start_date,order_end_date, count(distinct listener_id) over (partition by "AUDIOONLYtopctrbyweek37Q32015",week_of_year,order_id,oppty_amount,order_start_date,order_end_date) from (select "AUDIOONLYtopctrbyweek37Q32015", weekofyear(day) as week_of_year,op.order_id as order_id, 
oppty_amount, mv.order_start_date as order_start_date, mv.order_end_date as order_end_date,rdz.listener_id as listener_id 
from 
ROLLUP_PST rdz, 
dfp2ss mv, 
oppty_order_oline op where rdz.order_id = mv.dfp_order_id and mv.order_id = op.order_id and day >= '2015-09-07' and day <= '2015-09-13' 
and creative_size in ('2000x132','134x1285','2000x114')) z