Difference of values that belong to same group but stored in two rows
问题 I have a problem where i need to fetch 2 specific records with 2 different value and find the difference between their amount. This needs to be done for each device. Lets take the following table as example DevID reason amount DateTime -------------------------------------------------- 99 5 84 18-12-2016 18:10 99 0 35 18-12-2016 18:11 99 0 80 18-12-2016 18:12 99 0 34 18-12-2016 18:15 23 5 36 18-12-2016 18:16 23 4 22 18-12-2016 18:17 23 1 22 18-12-2016 18:18 23 2 22 18-12-2016 18:19 99 2 11 18