题解 | #截至当月的练题情况#

截至当月的练题情况

https://www.nowcoder.com/practice/80ed62a097564fad880b967678e460fc

select device_id,
date_format(event_date,'%Y-%m') as ym,
sum(count(1))over(partition by device_id order by date_format(event_date,'%Y-%m')) as sum_cnt,
round(avg(count(*))over(partition by device_id order by date_format(event_date,'%Y-%m') rows 2 preceding),2) as avg3_cnt,
sum(count(1))over(order by date_format(event_date,'%Y-%m')) as total_cnt
from question_practice_detail
group by device_id,date_format(event_date,'%Y-%m')
order by device_id,date_format(event_date,'%Y-%m')

窗口函数的综合应用,求三个月的平均数要用到rows 2 preceding,累加求和使用sum(count(1))然后正常分组求和即可

全部评论

相关推荐

03-13 21:15
江南大学 Java
多少分能进面啊?卡测评吗?做的我道心破碎了💔
小南瓜_66:A3 第四道题为什么用例过了 结果显示0%
投递携程等公司10个岗位 > 携程求职进展汇总
点赞 评论 收藏
分享
牛客963010790号:一般是hr拿着老板账号在招人不是真是老板招
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务