我知道在mysql中,我们可以禁用ONLY_FULL_GROUP_BY以对所选字段以外的其他字段进行聚合。但是在sql服务器中我不知道怎么做。
这是我尝试的查询:
select Arrival_Date, sum(Rate)
from Stay
Group by month(Arrival_Date)
我收到以下错误:
Msg 8120, Level 16, State 1, Line 2
Column 'Stay.Arr_Date' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.
尝试显示属于聚合组的每个日期是没有意义的。我想你想要:
select
Month = month(Arrival_Date),
Total = sum(Rate)
from
Stay
group by
month(Arrival_Date)