0

I know that in mysql we can disable ONLY_FULL_GROUP_BY to do aggregations in relation to other fields than the selected ones. But in sql server i don't know how.

Here is the query i tried :

select Arrival_Date, sum(Rate) 
from Stay
Group by month(Arrival_Date)

i got the followed error:

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.
Salim Lyoussi
  • 236
  • 3
  • 9

1 Answers1

0

It doesn't make sense to try so show each date that is part of the aggregated group. I think you wanted:

select 
    Month = month(Arrival_Date), 
    Total = sum(Rate) 
from 
    Stay
group by 
    month(Arrival_Date)
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541