Situation:
I have this table where I load items into a history, more or less like below:
| date | item | value |
|---------------------|------|-------|
| 2018-03-08 10:22:00 | A | 300 |
| 2018-03-08 10:22:00 | B | 3000 |
| 2018-03-08 10:22:00 | C | 30 |
| 2018-03-08 10:21:00 | A | 200 |
| 2018-03-08 10:21:00 | B | 2000 |
| 2018-03-08 10:21:00 | C | 20 |
| 2018-03-08 10:20:00 | A | 100 |
| 2018-03-08 10:20:00 | B | 1000 |
| 2018-03-08 10:20:00 | C | 10 |
And I need to calculate the differences between a item entry with the previous item entry, progamatically, resulting in
| date | item | value | diff |
|---------------------|------|-------|------|
| 2018-03-08 10:22:00 | A | 300 | 100 |
| 2018-03-08 10:22:00 | B | 3000 | 1000 |
| 2018-03-08 10:22:00 | C | 30 | 10 |
| 2018-03-08 10:21:00 | A | 200 | 100 |
| 2018-03-08 10:21:00 | B | 2000 | 1000 |
| 2018-03-08 10:21:00 | C | 20 | 10 |
| 2018-03-08 10:20:00 | A | 100 | 100 |
| 2018-03-08 10:20:00 | B | 1000 | 1000 |
| 2018-03-08 10:20:00 | C | 10 | 10 |
I had saw this link, and that sounded promising, but what I need is one that could build this historical series, because this value will be used into some Grafana dashboards for graphics... Any tips on how I could do this?
I'm using PostgreSQL 9.3 on Linux on System z