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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -