当我尝试对分区求和以得到每个阶段的总和时,它是分区的adds progressively through the rows。
select
sub_business,
channel,
stage,
time::date as time,
count(session_id) as count,
count / lag(count) over (partition by time::date, channel order by count desc) as conversion_rate,
sum(count) over (partition by stage, time::date order by count) as total
from
loan_dw_test.marketing.uploan_funnel_table
where
time::date = '2019-06-21'
and stage in ('application_view', 'lead')
group by
time::date,
sub_business,
channel,
stage
order by
time desc,
sub_business,
channel,
count desc
例如,我想要对所有application_view行获取总计57,对于所有潜在客户行获取62。
答案 0 :(得分:2)
为了计算每个分区的总和,您可以跳过ORDER BY
:
SELECT ...
,sum(count) over (partition by stage, time::date)
FROM ...