Is there any way to calculate the time difference in SQL between rows within the same column based on the 'DOWN' and 'UP' values like this:
There are 3 scenarios(that I'm aware of):
- Yellow, Orange and Green: there is a state_id 2(down) and after that a state_id 5(up), so the time difference needs to be calculated between the two rows;
- Blue: there are multiple state_id 2(down) and after that one state_id 5(up), so the time difference needs to be calculated between the first row and last row;
- Red: there is only a state_id 2(down) because it is still down with any update, so the time difference needs to be calculated till the end of the month.
I hope you can help me out.