我知道在mysql中我们可以禁用ONLY_FULL_GROUP_BY来执行与所选字段之外的其他字段相关的聚合。但在sql server中,我不知道如何。
这是我试过的查询:
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.
答案 0 :(得分:0)
尝试这样做是没有意义的,显示作为聚合组的一部分的每个日期。我想你想要:
select
Month = month(Arrival_Date),
Total = sum(Rate)
from
Stay
group by
month(Arrival_Date)