项目中的应用:
代码1:
计算代表的拜访次数,并将BU作为参考
select
t.staff_id,
t.cnt, sum(t.cnt) OVER (partition by BU ORDER BY BU) as bu_cnt
FROM
(
select
staff_id, bu, sum(interaction_cnt) as cnt-- ,
sum(interaction_cnt) OVER (partition by BU ORDER BY BU) as bu_cnt
from
互动拜访
where
bu is not null
group by
staff_id,bu
)t
代码2:
在BU内做排名
select
staff_id,
t.cnt, RANK() OVER(ORDER BY t.cnt DESC) AS '序号'
FROM
(
select staff_id, bu, sum(interaction_cnt) as cnt-- ,
sum(interaction_cnt) OVER (partition by BU ORDER BY BU) as bu_cnt
from
互动拜访
where
bu is not null
group by
staff_id,bu
)t