I have a dataset organized as follows: the columns are [date], [guid], and [value (int)]. Here’s an example of the data structure:
[date], [guid], [value]
10/1, guid1, 10
10/1, guid2, 5
10/2, guid1, 12
10/2, guid2, 14
10/3, guid1, 11
I am looking to extract results that show the difference in values for the same GUIDs across consecutive days. For instance, the desired outcome would look like this:
10/1, guid1, 2
10/1, guid2, 9
10/2, guid1, -1
This means for each GUID, I’m comparing today’s value against the value from the next day, then calculating the difference. For example, for the entry 10/1 and guid1, the calculation is:
10/1, guid1, 10
10/2, guid1, 12
Thus, the result for 10/1, guid1 is 12 - 10 = 2. How can I achieve this in SQL? Thanks!