有没有办法让 sum window 函数不通过分区逐步求和?
Is there a way to have a sum window function not progressively sum through the partition?
当我尝试对分区求和以获得每个阶段的总和时,它 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。
为了计算整个分区的总和,您可以跳过 ORDER BY
:
SELECT ...
,sum(count) over (partition by stage, time::date)
FROM ...
当我尝试对分区求和以获得每个阶段的总和时,它 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。
为了计算整个分区的总和,您可以跳过 ORDER BY
:
SELECT ...
,sum(count) over (partition by stage, time::date)
FROM ...