In SQL Server 2012, I have a table my_table that has columns state, month, ID, and sales.
my_table
state, month, ID
sales
My goal is to merge different rows
Considering there should be an index on column id, this query would be a better solution:
id
select state, month, id, sum(sales) Total from yourtable group by id, state, month order by id