WITH exp_type AS( SELECT exp_number, exp_type FROM express_tb ) --选取express的type SELECT b.exp_type, ROUND(avg(TIMESTAMPDIFF(MINUTE,a.out_time,a.in_time)/60),1) AS time FROM exp_action_tb AS a LEFT JOIN exp_type AS b ON a.exp_number=b.exp_number GROUP BY b.exp_type ORDER BY avg(TIMESTAMPDIFF(HOUR,a.out_time,a.in_time)) ASC;