Suppose we have the following input table

```
cat  | value | position
------------------------
1    | A     |   1
1    | B     |   2
1    | C     |   3
1    | D     |   4
2    | C     |   1
2    | B     |   2 
2    | A     |   3
2    | D     |   4

```

As you can see, the values `A,B,C,D` change `position` in each `category`, I want to track this change by adding a column `change` in front of each `value`, the output should look like this:

```
    cat  | value | position | change
    ---------------------------------
    1    | A     |   1      |  NULL
    1    | B     |   2      |  NULL
    1    | C     |   3      |  NULL
    1    | D     |   4      |  NULL
    2    | C     |   1      |   2
    2    | B     |   2      |   0
    2    | A     |   3      |  -2
    2    | D     |   4      |   0

```

For example `C` was in position `3` in category `1` and moved to position `1` in category 2 and therefore has a `change` of `2`. I tried inmplementing this using the `LAG()` function with an offset of 4 but I failed, how can I write this query.