在我的查询中,我试图每周带回前750个订单ID(按点击率)。
不是所有星期中的前750名。我无法弄清楚如何做到这一点。
select "topctrbyQ32015", weekofyear(day),order_id, (sum(clicks)/sum(impressions)) as ctr
from RDZ_TABLE rdz
where day >= '2015-07-06'
and day <= '2015-09-27'
group by "topctrbyQ32015", weekofyear(day),order_id
order by ctr desc
limit 750;
答案 0 :(得分:0)
您需要使用窗口函数(在Hive 0.11及更高版本中可用):
select
woy,
order_id,
ctr,
rank() OVER (partition by woy order by ctr desc) as ctr_rank
from
( select
weekofyear(day) as woy,
order_id,
(sum(clicks)/sum(impressions)) as ctr
from
RDZ_TABLE rdz
where
day >= '2015-07-06'
and day <= '2015-09-27'
group by
weekofyear(day),order_id
) z
where
rank() OVER (partition by woy order by ctr desc) <= 750