mysql query for selecting the result from one table and inserting in another table -


sir..can u plz tell me query plz

table1

-------------------------------- stock_name|temple|quantity|type -------------------------------- rice      |shiva |  32    |purchase rice      |shiva |  10    |issue wheat     |ganesh|  50    | purchase wheat     |ganesh|  45    | issue    ghee      |ganesh|  50    | purchase ghee      |ganesh|   5    | issue    

expected output in table2

-------------------------------- stock_name|temple|quantity| -------------------------------- rice      |shiva |  22    | wheat     |ganesh|  5     |  ghee      |ganesh|  45    | 

and here same answer in every other question posted

insert secondtable (stock_name,temple,quantity) select  stock_name,         temple,         sum(case when type = 'purchase'                       quantity                       else quantity * -1                   end) quantity    firsttable group   stock_name, temple 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -