SELECT
t.exp_type,
ROUND(AVG(TIMESTAMPDIFF(MINUTE,a.out_time,a.in_time)/60.0),1) AS time
FROM
exp_action_tb a
JOIN
express_tb t ON a.exp_number=t.exp_number
GROUP BY
t.exp_type
ORDER BY
time ASC
一开始我写的是AVG(SUM(...)),报错,因为:
- AVG本身就包含SUM再按group的类型取平均
- 这是两个同级别的聚合函数,不能嵌套使用。

京公网安备 11010502036488号