对于下表结构 预订 字段 - BookingID(主键),CustID,SeatPref
我想获得大多数CustID首选的SeatPref。
请帮忙。
答案 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
应该这样做。