I tried to adapt everything from Create a Cumulative Sum Column in MySQL to what I'm doing, but I can't seem to get it right. I am a newbie at MySQL and stackoverflow.com. My table looks like in the following example. I need to place a sum of previous rows of the AR column in each (1, 2, 3) column depending on time. So, in the "1" column I have to place a sum of all the previous AR cells but only when Time=01:00, in the "2" column I have to place a sum of all the previous AR cells but only when Time=02:00 and so on. The other cells from each (1, 2, 3) column should remain 0.00000.
My problem is that I can't find the proper syntax, considering that I can't find a way to replace the "id" from the examples posted on the specified topic.
LE: I also found this How to do a sum of previous rows in mysql but I have no idea what should I change in it to get the desired result. I simply don't understand where each notation comes from (e.g.: r.row1, t2.row1, requete r2, cumesum etc.)
Can someone help me, please?
Thank you!
Sample table:
| Time | AR | 1 | 2 | 3 |
|:-----|:---|:--|:--|:--|
|00:00 |0.12|0 |0 |0 |
|01:00 |0.16|0 |0 |0 |
|02:00 |0.13|0 |0 |0 |
|03:00 |0.19|0 |0 |0 |
|04:00 |0.11|0 |0 |0 |
|00:00 |0.15|0 |0 |0 |
|01:00 |0.34|0 |0 |0 |
|02:00 |0.56|0 |0 |0 |
|03:00 |0.67|0 |0 |0 |
|04:00 |0.92|0 |0 |0 |
Desired table:
| Time | AR | 1 | 2 | 3 |
|:-----|:---|:--------|:--------|:--------|
|00:00 |0.12|0 |0 |0 |
|01:00 |0.16|0.16 |0 |0 |
|02:00 |0.13|0 |0.13 |0 |
|03:00 |0.19|0 |0 |0.19 |
|04:00 |0.11|0 |0 |0 |
|00:00 |0.15|0 |0 |0 |
|01:00 |0.34|0.16+0.34|0 |0 |
|02:00 |0.56|0 |0.13+0.56|0 |
|03:00 |0.67|0 |0 |0.19+0.67|
|04:00 |0.92|0 |0 |0 |