例如,我不確定如何找到計數函式的最大值
Select Count(Seat_Reservation.Customer_phone) as MaxTicketsBooked
, Seat_Reservation.Customer_phone
From Seat_Reservation
Group By Seat_Reservation.Customer_phone
Having Count(Seat_Reservation.Customer_phone) = (
Select MAX(MaxTicketsBooked)
From (
Select Count(Seat_Reservation.Customer_phone) As MaxTicketsBooked
From Seat_Reservation
Group By Seat_Reservation.Customer_phone
) As Maxed
);
此代碼對我有用,但是,我需要顯示產生錯誤的 CustomerNames:列 'Seat_Reservation.Customer_name' 在選擇串列中無效,因為它既不包含在聚合函式或 GROUP BY 子句中。
有沒有一種方法可以找到由
Select Count(Seat_Reservation.Customer_phone) as MaxTicketsBooked,
先感謝您!
uj5u.com熱心網友回復:
您沒有發布失敗的代碼,所以我猜:
Select Count(Seat_Reservation.Customer_phone) as MaxTicketsBooked
, Seat_Reservation.Customer_phone
, Seat_Reservation.Customer_name
From Seat_Reservation
Group By Seat_Reservation.Customer_phone
Having Count(Seat_Reservation.Customer_phone) = (
Select MAX(MaxTicketsBooked)
From (
Select Count(Seat_Reservation.Customer_phone) As MaxTicketsBooked
From Seat_Reservation
Group By Seat_Reservation.Customer_phone
) As Maxed
);
并且錯誤訊息非常有意義。
Column 'Seat_Reservation.Customer_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
解決方案就在錯誤訊息中。
Select Count(Seat_Reservation.Customer_phone) as MaxTicketsBooked
, Seat_Reservation.Customer_phone
, Seat_Reservation.Customer_name
From Seat_Reservation
Group By Seat_Reservation.Customer_phone
, Seat_Reservation.Customer_name
Having Count(Seat_Reservation.Customer_phone) = (
Select MAX(MaxTicketsBooked)
From (
Select Count(Seat_Reservation.Customer_phone) As MaxTicketsBooked
From Seat_Reservation
Group By Seat_Reservation.Customer_phone
) As Maxed
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/451041.html
