Such as A table
Pid pNum
1 5
2 10
3 20
It is best to use SQL statements, the result of the 20-10-5, from the bottom, in turn, is presupposed, and the data line is not fixed,
You have any good method, the younger brother novice, warrior, please help
CodePudding user response:
Pid pNum1-5
2-10
3 20
Handle like this
CodePudding user response:
So to imagine the last line of the not, then the SUM of the columnCodePudding user response:
Use cursor, take when data is arranged in reverse chronological order, and then how to deal with, is very simpleCodePudding user response:
Select sum (pnum)The from (
Select - 1 * sum (pnum) pnum
The from tablename
Union all
Select 2 * pnum pnum
The from tablename
Where pid=(select Max (pid) from tablename)
) tabletmp