PostgreSQL Query to get the output from same table with same table values -


i have 1 table

id  employee    leave_days  leave_type  type 1   abc                 10       sick   remove 2   abc                 20       sick   add 3   abc                 15     annual   remove 4   abc                 50     annual   add 5   xyz                 10       sick   remove 6   xyz                 20       sick   add 7   xyz                 15     annual   remove 8   xyz                 50     annual   add 

from above table group column name called leave_type , merge rows , output should follows.

i have group column name leave_type , add new column called leave_allocated . in leave_allocated column, column type value add come.

id  employee    leave_days  leave_type  leave_allocated 1   abc             10          sick    20 2   abc             15        annual    50 3   xyz             10          sick    20 4   xyz             15        annual    50 

i tried sub query not match inner query outer query .

this should help

select id,     employee,     leave_dates,     leave type,     (select leave_days     table t2     t2.id = t1.id     , t2.type = 'add'     ) leave_allocated table t1 t1.type = 'remove' 

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 -