sql - MYSQL query for selecting the result of a condition of one table and showing it on another table -


the 2nd row should subtracted 1st row...and display result in 2nd table

1st table

-------------------------------- stock_name|temple|quantity|type -------------------------------- rice      |shiva |  32    |purchase rice      |shiva |  10    |issue 

initially 2nd table empty

what need in 2nd table follows

--------------------------- stock_name|temple|quantity -------------------------- rice      |siva  |22 

insert table2(stock_name,temple,quantity) select a.stock_name, a.temple, sum(case when type='purchase' quantity else (quantity*-1) end) quantity table1 group a.stock_name, a.temple 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -