我有三张桌子:
accounts: `account_id`, `donations_req`, `payments_in, balance`
donations_required: `donation_id`, `charity_id`, `account_id`, `amount`, `status`, `date`
payments: `payment_id`, `account_id`, `amount`, `date`
donations_req我已经设法将每个捐助者的所有内容加起来并覆盖该donations_req字段以及该字段的付款,payments_in然后是余额(payments_in - donations_req)。
但是我需要的是;使用payments_in总数,循环遍历donations_required(按 排序)的列表,并将已支付的date更改为 1。status
例如:如果我有 3 笔捐款,每笔 50 美元,我存入 120 美元。余额为 -$30,前两次捐款应标记为已付款。
donations_required那么,考虑到表中完全有不同的帐户,我该如何标记这样的状态。
我什至需要存储过程吗?