This is my first post here! I am dealing with this query for a while now and I really need your help.
I have 2 tables
Counters
=============
ID Description
-------------------
1 GasCounter1
2 GasCounter2
Measurements
================
ID TimeStamp ValCum CounterID
----------------------------------------------
1 01.01.2015 00:00:00 1 1
2 01.01.2015 00:15:00 2 1
3 01.01.2015 00:30:00 3 1
4 01.01.2015 00:45:00 4 1
---------------------------------------
5 01.01.2015 01:00:00 5 1
6 01.01.2015 01:15:00 6 1
7 01.01.2015 01:30:00 7 1
8 01.01.2015 01:45:00 8 1
---------------------------------------
9 01.01.2015 02:00:00 9 1
10 01.01.2015 02:15:00 10 1
11 01.01.2015 02:30:00 11 1
12 01.01.2015 02:45:00 12 1
---------------------------------------
13 01.01.2015 03:00:00 13 1
14 01.01.2015 03:15:00 14 1
15 01.01.2015 03:30:00 15 1
16 01.01.2015 03:45:00 16 1
---------------------------------------
17 01.01.2015 04:00:00 17 1
18 01.01.2015 04:15:00 18 1
19 01.01.2015 04:30:00 19 1
20 01.01.2015 04:45:00 20 1
.... Here are data only for GasCounter1
ValueCum is cumulative consumption read from GasCounters
I need to calculate gas consumptions for each hour (from selected interval) In this example all consumptions are 4.
1->2 = 1 +
2->3 = 1 +
3->4 = 1 +
4->5 = 1 = ===> 4
5->6 = 1
6->7 = 1
7->8 = 1
8->9 = 1 ===> 4
If actual data were:
5->6 = 1
6->7 = 1
7->9 = 2
9->12 = 3 ===> 7
Well I tried with Group by --> I can calculate group sums, but that is wrong. While I was google-ing around I found some solution for running total and cumulative sum, but this is right the oposite of what I need.
I already have cumulative values -> I need the difference between:
last record in **previous** group and
last record inside current group
I hope I was clear about the problem. Appreciate your help
If I get your question right, maybe this will be the thing your looking for.