SQL174 2021年国庆在北京接单3次及以上的司机统计信息
问题:请统计2021年国庆7天期间在北京市接单至少3次的司机的平均接单数和平均兼职收入(暂不考虑平台佣金,直接计算完成的订单费用总额),结果保留3位小数
SELECTcity,ROUND(SUM(order_num)/COUNT(driver_id),3) AS avg_order_num,ROUND(SUM(income)/COUNT(driver_id),3) AS avg_income
FROM
(SELECTcity,driver_id,COUNT(order_time) AS order_num,SUM(fare) AS incomeFROM tb_get_car_order JOIN tb_get_car_record USING(order_id)WHERE city='北京'AND DATE(order_time) BETWEEN 20211001 AND 20211007GROUP BY driver_id
) AS A
WHERE order_num>=3
GROUP BY city
SQL175 有取消订单记录的司机平均评分
问题:请找到2021年10月有过取消订单记录的司机,计算他们每人全部已完成的有评分订单的平均评分及总体平均评分,保留1位小数。先按driver_id升序输出,再输出总体情况
SELECTdriver_id,ROUND(AVG(grade),1) AS avg_grade
FROM tb_get_car_order
WHERE grade IS NOT NULL
AND driver_id IN (SELECT driver_id FROM tb_get_car_order WHERE start_time IS NULL AND DATE(order_time) BETWEEN 20211001 AND 20211031)GROUP BY driver_id
UNION
SELECT'总体' AS driver_id,ROUND(AVG(grade),1) AS avg_grade
FROM tb_get_car_order
WHERE grade IS NOT NULL
AND driver_id IN (SELECT driver_id FROM tb_get_car_order WHERE start_time IS NULL AND DATE(order_time) BETWEEN 20211001 AND 20211031)ORDER BY IF(driver_id='总体',1,0),driver_id