我需要一个函数或触发器来解决这个问题??
顾客信息 :::
custid name creditid
----------------------------
2 a 1
3 b 2
4 c 3
余额 :::
creditid credit_type balance
-----------------------------------
1 rent 1000
1 transport 2000
1 food 1000
1 fruits 1500
2 rent 1500
2 transport 1020
2 food 1200
2 fruits 1000
3 transport 1600
3 rent 2000
3 food 1540
3 fruits 1560
Pay_the_loan :::
creditid credit_type Pay status
---------------------------------------------
1 rent 500 null
2 fruits 600 null
3 transport 400 null
1 fruits 500 null
一旦我将status
列更新pay_the_loan table
为ok
特定的creditid
即,
(更新 pay_the_loan set status='ok' where creditid=2)
then
它应该是 balance_amount 表deduct
中列中的金额,balance
并且应该更新,即(1000-600=400
在 balance_amount 表中where
balance_amount.credit_type=fruits 和 creditid=2 来自余额表)
可以给我发一个Function
或一个Trigger
来解决这个问题吗?