构建表结构的SQL查询

时间:2011-02-17 14:27:54

标签: sql mysql

对于下表结构 预订 字段 - BookingID(主键),CustID,SeatPref

我想获得大多数CustID首选的SeatPref。

请帮忙。

2 个答案:

答案 0 :(得分:6)

select
    seatpref,
    count(seatpref) as PrefCount
from
    Bookings b
group by
    seatpref
order by
    count(seatpref) desc

答案 1 :(得分:2)

我认为

SELECT SeatPref, count(SeatPref) AS NumCusts
FROM your_table
GROUP_BY SeatPref
ORDER_BY NumCusts

应该这样做。