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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -