postgresql - Delete rows where data has less sum -


i have following table:

 data_id    sum_value     xxx        30     xxx        40     ccc        50     aaa        60     ccc        70     aaa        80     ddd        100     eee        200 

how delete row data_id = data_id , sum < sum ? delete rows if data_id = data_id , sum_value less , if data_id != data_id show actual values

expected output

data_id   sum_value xxx      40 ccc      70 aaa      80 ddd      100 eee      200 

thank

delete foo  using(select min(sum_value) sum             ,data_id       foo       group data_id        having count(data_id)>1      )t foo.sum_value=t.sum        , foo.data_id=t.data_id   

sqlfiddle - demo


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -