我有一张如下表
Value Count
value1 55
value2 60
value3 65
value4 20
value5 25
value6 45
value7 5
value8 25
我需要一个查询来获取两个连续计数之间的差异并将它们相加。一个条件是,如果下一个值小于前一个值,则考虑下一个值而不是差值。工作如下
Value Count Diff Explanation
value1 55 No diff as there is no previous value
value2 60 5 (60-55)
value3 75 15 (75-60)
value4 20 20 (20 as 20 < 75)
value5 25 5 (25-20)
value6 45 20 (45-25)
value7 5 5 (5 as 5 < 45)
value8 25 20 (25-5)
查询应该给出所有差异的总和,即5+15+20+5+20+5+20 = 90
提前感谢您为我制作的精彩查询:-)