题解 | 饿了么需要分析不同配送员在不同天气条件下的配送效率和用户投诉情况

饿了么需要分析不同配送员在不同天气条件下的配送效率和用户投诉情况

https://www.nowcoder.com/practice/e27ba25e7722478eb86c832fab96fc1a

SELECT
    weather_type,
    ROUND(AVG(delivery_time), 2) AS average_delivery_time,
    COUNT(*) AS delivery_count
FROM
    delivery_records
    JOIN weather_conditions USING (weather_id)
WHERE
    staff_id IN (
        SELECT
            staff_id
        FROM
            (
                SELECT
                    weather_type,
                    staff_id
                FROM
                    delivery_records
                    JOIN delivery_staff USING (staff_id)
                    JOIN weather_conditions USING (weather_id)
                GROUP BY
                    weather_type,
                    staff_id
                HAVING
                    AVG(average_speed) > 20
                    AND SUM(is_complaint) / COUNT(record_id) < 0.5
            ) AS t1
    )
GROUP BY
    weather_type
ORDER BY
    weather_type ASC;

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务