题解 | 查询高价值旅行套餐客户的支出与套餐详情
查询高价值旅行套餐客户的支出与套餐详情
https://www.nowcoder.com/practice/957e8ab30e2745b48d2f79046df73a23
SELECT c.name AS customer_name, SUM(price) AS total_travel_cost, COUNT(customer_id) AS order_count, ROUND((SUM(price)/COUNT(customer_id)),2) AS avg_order_price FROM bookings b JOIN packages p ON b.package_id = p.id JOIN customers c ON b.customer_id = c.id where booking_date BETWEEN '2024-01-01' and '2024-12-31' GROUP BY c.name HAVING total_travel_cost > 10000 order by total_travel_cost desc;