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

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

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

#1)筛选条件有2个,①日期是2021年11月,所以要将in_time字段转换成年+月形式的字符串,使用date_format(日期,日期格式)函数;②过滤atrticle_id不为0的数据;
#2)根据日期分组,但日期本身是长日期格式,要转换成短日期,可以使用date(日期)函数;
#3)人均浏览文章时长=文章浏览总时长/总人数,因为是人均,而每人可能读多篇,所以要对uid去重;
#4)取总时长时,使用timestampdiff(时间单位,开始时间,结束时间)函数来计算
#5)结果如下:
select date(in_time) as dt,
round(sum(timestampdiff(second,in_time,out_time))/count(distinct uid),1) as avg_viiew_len_sec
from tb_user_log t
where date_format(in_time,"%Y-%m")  = "2021-11"
and artical_id != 0
group by dt 
order by avg_viiew_len_sec;

全部评论
select那里date和date_format(in_time,"%Y%m")哪个更好用啊,感觉都差不多
点赞
送花
回复
分享
发布于 04-08 11:06 广西

相关推荐

中信银行 AI算法岗 29~32w
点赞 评论 收藏
转发
头像
点赞 评论 收藏
转发
4 3 评论
分享
牛客网
牛客企业服务