题解 | #2021年11月每天的人均浏览文章时长#
2021年11月每天的人均浏览文章时长
https://www.nowcoder.com/practice/8e33da493a704d3da15432e4a0b61bb3
#需求:2021年11月每天的人均浏览文章时长(秒数) #输出:日期、人均浏览文章时长 #要求:时间范围为2021年11月;avg_viiew_len_sec保留一位小数,升序输出; #特殊点:artical_id-文章ID为0表示用户在非文章内容页,不计入时长计算 select date_format(out_time,'%Y-%m-%d') dt, round(sum(timestampdiff(second,in_time,out_time))/count(distinct uid),1) avg_viiew_len_sec from tb_user_log where date_format(out_time,'%Y-%m')='2021-11' and artical_id<>0 group by 1 order by 2 #总结:人均浏览时长计算不能使用avg,直接avg,它的分母是group by后的天数,得到的是日均时长,要求人均则需要对人数去重count计数
查看7道真题和解析