问题:
统计2021年11月每天的人均浏览文章时长(秒数),结果保留1位小数,并按时长由短到长排序。
问题分解:
- 2021 年11月
date_format(in_time,'%Y-%m')='2021-11'
- 每天浏览文章时长
select date(in_time) dt,sum(timestampdiff(second,in_time,out_time))
from tb_user_log
where date_format(in_time,'%Y-%m')='2021-11' and artical_id !=0
group by dt
- 每天浏览人数
select date(in_time) dt,count(distinct uid)
from tb_user_log
where date_format(in_time,'%Y-%m')='2021-11'
group by dt
- 当artical_id=0时需要剔除时长计算
where artical_id !=0
- 汇总
select date(in_time) dt,
round(sum(timestampdiff(second,in_time,out_time))/count(distinct uid),1) avg_viiew_len_sec
from tb_user_log
where date_format(in_time,'%Y-%m')='2021-11' and artical_id != 0
group by dt
order by avg_viiew_len_sec