如何汇总特定航班的总预订量

How to sum total bookings for a particular flight

好的,所以我在 table 中有两列。其中之一表示客户预订了多少人去某个特定国家/地区。 另一列显示订单预订的国家,例如斐济、澳大利亚。 我在添加 No_Of_People 列以确定哪个航班目的地的人数最多时遇到了麻烦。 如果每个国家/地区只有一个预订,这将很容易,因为它会是这样的:

select destination_name from bookings order by sum(No_Of_People) desc limit 1;

只是想知道如何才能做到这一点,因为我知道有多个人预订同一个国家/地区。

select sum(No_Of_People), destination_name from bookings group by destination_name order by sum(No_Of_People) desc

您需要按目的地分组以获得每个目的地的人数:

SELECT
  destination_name,
  sum(No_Of_People) AS count
FROM
  bookings
GROUP BY destination_name
ORDER BY count desc;

https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html