mysql中update實現子查詢的方法
錯誤:
1 update account_list
2 set PaidIn = select sum(Penalty) from pay_rec where CerID = '1006840113' and Processed = 0,
3 Way = '现金'
4 where PaidIn = 0.00;
正確:
1 update account_list a,
2 (select sum(Penalty) as P from pay_rec where CerID = '1006840113' and Processed = 0 group by Processed) b
3 set a.PaidIn = b.P,
4 a.Way = '现金'
5 where a.BillID = '20120102160851';