Since it was not mentioned here. The above answers are correct, that is, the order of the columns after the "group by" clause will not affect the correctness of the request (ie, Amounts).
However, the order of the resulting rows will vary depending on the order of the columns specified after the group by clause. For example, consider table A with the following lines:
Col1 Col2 Col3 1 xyz 100 2 abc 200 3 xyz 300 3 xyz 400
SELECT *, SUM(Col3) FROM A GROUP BY Col2, Col1 will retrieve rows sorted by Col2 in ascending order.
Col1 Col2 Col3 sum(Col3) 2 abc 200 200 1 xyz 100 100 3 xyz 300 700
Now change the order of the columns in the group to Col1, Col2 . The resulting rows are ordered using Col1 .
i.e. select *, sum(Col3) from A group by Col1, Col2
Col1 Col2 Col3 sum(Col3) 1 xyz 100 100 2 abc 200 200 3 xyz 300 700
Note. The summation sum (i.e. the correctness of the request) remains exactly the same.
AaCodes Aug 31 '16 at 23:08 2016-08-31 23:08
source share