题解 | #2021年11月每天的人均浏览文章时长#

2021年11月每天的人均浏览文章时长

http://www.nowcoder.com/practice/8e33da493a704d3da15432e4a0b61bb3

select
    date(in_time) dt,
    round(sum(timestampdiff(second,in_time,out_time)) / count(distinct uid),1) avg_lensec
from tb_user_log
where date_format(in_time,"%Y-%m") = "2021-11" and artical_id  != 0
group by dt
order by avg_lensec 





全部评论
为什么这里group by后面可以用别名啊
2 回复 分享
发布于 2024-04-21 21:55 北京
题目有一定的歧义,人均浏览时间,如果一个用户登录了,没有浏览文章,他计时为0,还是说就不算了。当前这个代码的意思是不算了。
1 回复 分享
发布于 2022-12-19 18:23 北京
为什么这样写不行呢? select round(avg(sum(TIMESTAMPDIFF(second,in_time,out_time)) over partition by uid),1) as avg_viiew_len_sec, date(in_time) as dt from tb_user_log group by dt order by avg_viiew_len_sec desc
点赞 回复 分享
发布于 2022-04-06 15:27
为什么要 artical_id != 0呀?数据的 artical_id都不为零呀
点赞 回复 分享
发布于 2023-01-06 10:00 湖南
where date_format(in_time,"%Y-%m") = "2021-11" and artical_id != 0 为什么用的双引号,我复制进去牛客把%Y-%m") = "2021-11识别成一整个字符串了
点赞 回复 分享
发布于 2023-02-10 16:16 浙江
为什么不能用avg函数, AVG(TIMESTAMPDIFF(SECOND, in_time, out_time)) AS avg_lensec 这样可以吗
点赞 回复 分享
发布于 2024-04-11 16:47 北京
跨天了可能会有坑,比如一个视频的浏览时间是从 2021-11-02 23:55:00 ~ 2021-11-03 00:05:00,这么算会把11-03的部分时间算到11-02内去
点赞 回复 分享
发布于 2024-11-04 21:10 广东

相关推荐

云边有个小卖铺儿:校招生违约率低,所以我要高😂
点赞 评论 收藏
分享
评论
37
1
分享

创作者周榜

更多
牛客网
牛客企业服务