0

我知道在 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.
4

1 回答 1

0

尝试显示属于聚合组的每个日期是没有意义的。我想你想要:

select 
    Month = month(Arrival_Date), 
    Total = sum(Rate) 
from 
    Stay
group by 
    month(Arrival_Date)
于 2017-05-10T03:15:11.600 回答