Skip to content
Advertisement

Compare the rows value in a single column and update the flag accordingly in SQL-Server table

I have one table as below

I need to group on A,B and C and need to sum the value of E, example table below how it looks after summing up

I need to compare the SumValue by grouping A,B,C of first row which C has 0 with the second row which C has 1 and which ever has the lowest value those records should come as 1 in E column rest of the records should come as 0 in E column. If the SumValue is same whereas in the last two rows then E column should come as 1 where C is 1 and E column should come as 0 where C is 0.

The output I need is like this…All I need to do in this scenario is updating E column..

Scripts to create table and insert data

If you have any questions on this query, please let me know

Advertisement

Answer

If I understand correctly:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement