sql - How to find the difference between 2 rows -


table1

id no name value  001 grid1 rajan 200 001 grid2 rajan 300 002 grid1 mahesh 100 002 grid2 mahesh 200 003 grid1 jayan 200 003 grid2 jayan 50 

i want find difference (grid1 - grid2) each id

expected output

id  name value  001 rajan -100 002 mahesh -100 003 jayan 150 

how make query above condition

need query help

select id, name, sum(case when no = 'grid1' value else value*(-1) end) table1 group id, name 

see sql fiddle demo


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -