#2、根据第一步处理的结果,进行进一步的处理# select t1.dt, #2.1、注意:分母为“每天”各文章的总浏览时长,分母为观众人数(可能存在1天1人多条浏览记录,因此需要去重)# round(sum(t1.viiew_len_sec) / count(distinct t1.uid),1) as avg_viiew_len_sec from #1、首先,按照需求确定所需数据表,以及展示字段# #1.1、uid作为后续分母的计数依据,需要挑选出来;根据展示字段,用date_format提取出相应日期形式;每篇文章的浏览时长(不区分天),在统计每天平均时长时提前计算出来。# (select uid,date_format(in_time,'%Y-%m-%d') as dt, timestampdiff(second,in_time,out_time) as viiew_len_sec from tb_user_log #1.2、①2021年11月;②artical_id-文章ID为0表示用户在非文章内容页# where date_format(in_time,'%Y-%m') = '2021-11' and artical_id != 0) as t1 group by 1 order by 2