I have a query with sum in it as follows:
SELECT Table1.ID, SUM(Table2.[Number1] + Table2.[Number2]) AS SumColumn FROM Table1 INNER JOIN Table3 ON Table1.ID = Table3.ID INNER JOIN Table2 ON Table3.ID = Table2.ID WHERE (Table2.[Something] = 'Whatever') GROUP BY Table1.ID, Table2.[Number1] , Table2.[Number2]
and he gives me a table like this:
ID SumColumn 67 1 67 4 70 2 70 6 70 3 70 6 80 5 97 1 97 3
How can I get him to give me a table like this, where the total amount grouped by ID column is summed?
ID SumColumn 67 5 70 17 80 5 97 4
I cannot GROUP BY SumColumn because I get an error (invalid column name "SumColumn".) COALESCE does not work either. Thanks in advance.
EDIT:
Just grouping by id gives me an error:
[Number1, Number2, and other column names that I select] are not allowed in the select list because it is not contained in the aggregate function or in the GROUP BY clause.
EDIT 2
I don't know why, but just grouping by Table.ID now works. Thanks to everyone who posted the correct answer, I would like me to notice them all!
source share