Skip to main content

runningDifference

Calculates the difference between successive row values ​​in the data block. Returns 0 for the first row and the difference from the previous row for each subsequent row.

Syntax​

runningDifference(expression)

Arguments​

ArgumentsDescription
expressionAny expression which generates numberic result, including integer numbers, real numbers, date and datetime.

Return Type​

Numberic Type

Examples​

databend :) DESC runing_difference_test;
β”Œβ”€Field─┬─Type──┬─Null─┐
β”‚ a β”‚ UInt8 β”‚ NO β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

databend :) SELECT * FROM runing_difference_test;
β”Œβ”€β”€a─┐
β”‚ 1 β”‚
β”‚ 3 β”‚
β”‚ 5 β”‚
β”‚ 10 β”‚
β””β”€β”€β”€β”€β”˜
β”Œβ”€β”€a─┐
β”‚ 15 β”‚
β”‚ 20 β”‚
β””β”€β”€β”€β”€β”˜

databend :) SELECT runningDifference(a) FROM runing_difference_test;
β”Œβ”€runningDifference(a)─┐
β”‚ 0 β”‚
β”‚ 2 β”‚
β”‚ 2 β”‚
β”‚ 5 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€runningDifference(a)─┐
β”‚ 0 β”‚
β”‚ 5 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜