Select sum until a set amount and then update fields in mysql database
问题 item_id rate status --------- ----------- ------ 1 12 credit 2 10 credit 3 10 credit 4 20 cash 5 55 credit I have the above table, A user inputs and amount of 25. Now I want to update the status of the rows having credit as status from credit to cash until the sum of rate is 25, so in the above table the top 1 rows having a sum of 22 should get a status of cash. Since the user input is 25, I still have a balance of 3 (25-22), this balance should be deducted from the third row making the third