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
Post a Comment