sql - Find highest in a group and update a column based n that -


simplified example: table has 4 columns: id, name, amount , parent. see image.

the parent column, in actual table, empty , needs populated entries column "name".

id non unique column multiple entries in column 'name' having same id.

the goal find maximum value entry in column "amount" id , populate column "parent" entry in column "name". post picture of example table in comments

enter image description here

the technique rank names within each id amount in subquery , join source table update:

update my_table set "parent"="name" (     select id,"name",row_number() on (partition id order "amount" desc)     my_table ) t my_table.id=t.id , t.row_number=1 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -