实时计算占比的问题

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

实时计算占比的问题

star
一张表做自关联,然后求两个粒度的占比;比如下面求月销数额占年销售额的比例,appendTable是从上游用滚动窗口计算的流注册的,tumble_end_time是某个窗口的结束时间,请问这样inner join 会丢数据吗?有更好的方法计算占比吗?

select months,monthAmount/yearAmount as amountRate from
(select months,years,amount as monthAmount,tumble_end_time from appendTable) a
join
(select years,tumble_end_time,sum(amount) as yearAmount from appendTable group by years,tumble_end_time)b
on a.years=b.years and a.tumble_end_time=b.tumble_end_time
;