题解 | #牛客直播各科目平均观看时长#
牛客直播各科目平均观看时长
https://www.nowcoder.com/practice/e9e7dc4c8623467793f6999cbfee9360
# 求每个科目的平均观看时长,单位是分钟 # 先对上课情况表的时长求秒数,再联结两张表,分组求均值 # 求均值,再除以60得到分钟单位 SELECT course_name, ROUND(AVG(time_gap)/60, 2) avg_Len FROM course_tb JOIN ( # 求时差 SELECT course_id, TIMESTAMPDIFF(SECOND, in_datetime, out_datetime) time_gap FROM attend_tb ) a USING(course_id) GROUP BY course_name ORDER BY avg_Len DESC