I have a table (sample) with 10 rows, that has columns of place_name, 5 days worth of data (day1, day2,...,day5) for each location, and a sum column (TotalSum) of the 5 days. TotalSum at the beginning is full of null values.
place_name | day1 | day2 | day3 | day4 | day5 | TotalSum
PlaceA | 1 | 1 | 1 | 1 | 1 | NULL
update sample set sample.TotalSum = day1+day2+day3+day4+day5;
SELECT place_name, MAX(TotalSum) AS MAXsum FROM sample;
"Column 'sample.place_name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
SELECT MAX(TotalSum) AS MAXsum FROM sample;
the reason you are getting this message is you are trying to aggregate the column
TotalSum but you also have a non agregated column
place_name. but you are not defining the group which the column can be aggregated by in a
GROUP BY clause
SELECT place_name, MAX(TotalSum) AS MAXsum FROM sample GROUP BY place_name