I have a MySQL 8 database table like this:
+-------+
| Total |
+-------+
| 100 |
+-------+
| 40 |
+-------+
I want to get the difference between the rows -> result = (row - (row + 1)) Before the math operation I always have only two rows.
My desired result is something like this:
+--------+
| Result |
+--------+
| 60 |
+--------+
What is the best way to do this?
I came up with something like this:
SELECT ABS( (a.total - LEAD(a.total,1,0) OVER(ORDER BY t.total) )) AS result FROM (...) a LIMIT 1
Before the math operation I always have only two rows.