lundi 4 janvier 2016

Update Sql field according to insertion

Hello guys I have 3 tables, med_list, med_receive and med_issue.

med_list

   -----------------------------------
   | med_id | med_name | med_balance |
   -----------------------------------

med_receive

med_amount is the amount received.

   -----------------------------------
   | med_id | med_batch | med_amount |
   -----------------------------------

med_issue

med_amount here is the amount issued.

   -----------------------
   | med_id | med_amount |
   -----------------------

now the med_balance in table med_list should be equal to sum of received med - sum of issued med.

The user directly adds into the receive and issue table. My qustion is, I can is automate the update of the med_balance for all med?

For example: Lets say we have med with name X and its balace is 0. If the user enters a receive of 100 tablets for that med, the med_balace should automatically update to 100.

Thank You, for your help.

Aucun commentaire:

Enregistrer un commentaire