The data in the table is the user's consumption points record, there is an increase, there is a decrease in consumption, I want to count a user's existing points, sum how to achieve it? No acoustic SQL.
Reply content:
The data in the table is the user's consumption points record, there is an increase, there is a decrease in consumption, I want to count a user's existing points, sum how to achieve it? No acoustic SQL.
Must there be a field for the record to be increased or decreased? Otherwise, how do you know whether to increase or decrease the points?
If the Type field 0 represents a decrease, 1 represents an increase, then
M (' Points ')->where (' type=1 ')->sum ();
If it is two fields Add_score and Reduce_score, then subtract two sum, if it is one, there must be a negative, direct sum.
If there is a field name in the table to determine whether it is increased or decreased, then use the Where to belong to the user, and is the increment of sum (), and then use a where to belong to the user and is a reduced sum (), then subtract it.
If there is no field to determine whether to increase or decrease, but instead of using the number of its own points consumption plus positive and negative storage, then the direct where belongs to the user's records and then sum can be