select exp_type,round(avg(duration),1) AS time FROM( SELECT a.exp_type,round(TIMESTAMPDIFF(MINUTE,b.out_time,b.in_time)/60,1) AS duration FROM express_tb AS a JOIN exp_action_tb AS b ON a.exp_number = b.exp_number ) AS c GROUP BY exp_type ORDER BY time ASC
此题ez,先通过表联选出每个商品的类型和运送时间(由于要保留一位小数所以我用的是时间相减取分钟数再除以60得到间隔小时数),然后就可以GROUP BY + avg聚合函数解决了