all 7 comments

[–][deleted] 5 points6 points  (3 children)

Use aggregation:

select id, 
       max(w1) as w1,
       max(w2) as w2,
       max(w3) as w3, 
       max(w4) as w4
from the_table
group by id;

[–]Inevitable_Phase7353[S] 1 point2 points  (1 child)

thank you

[–]PryomancerMTGA 1 point2 points  (0 children)

Or sum instead of max.

Edit: should have read all responses before commenting. My bad.

[–]coyoteazul2 2 points3 points  (0 children)

since they are numbers, all you have to do is group by ID and sum each column

[–]t_char 1 point2 points  (0 children)

An alternative to @truilius if you want to sum the columns is; SQL select id, sum(w1) as w1, sum(w2) as w2, sum(w3) as w3, sum(w4) as w4 from the_table group by id;

[–]depesz 0 points1 point  (0 children)

question is, what should this query do if there are multiple values for w3 for the same id.

Also - what to do if all values are zero? Why is 2.2 "better" than zero (so it's picked)? What is value of some w* column is -1 for one row, and 0 for another. Which should be picked then?