下面是我的查询。
alter Proc Rp_ByVehicleNo
@Vehicle_Number nvarchar(50),
@DateFrom datetime,
@DateTo datetime
as
select Vehicle_Number,Vehicle_Booking_Date,Time_From,Time_To,KM_Start,KM_End,
Total,
SUM(Total) as tot, Vehicle_Used_By,Cost_Code
from mtblLog_Book
where Vehicle_Number=@Vehicle_Number and
Vehicle_Booking_Date between @DateFrom and @DateTo
order BY Vehicle_Booking_Date
显示错误
列'mtblLog_Book.Vehicle_Number'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
答案 0 :(得分:0)
您的查询包含聚合函数SUM(Total)
,但未包含GROUP BY
语句。如果所有表都需要SUM,则不应在选择列表中包含其他字段。否则,如果您需要按这些字段分组并计算SUM
,则应在查询中添加GROUP BY Vehicle_Number,Vehicle_Booking_Date,Time_From,Time_To,KM_Start,KM_End,Total,Vehicle_Used_By,Cost_Code
。