I’ve the following values in my Table1 :
Date | Time | Id | Value | Unit |
---|---|---|---|---|
2024-01-01 | 06:00:10 | Key_001_C | 1557 | kWh |
2024-01-01 | 06:00:01 | Key_002_01_C | 10323 | kWh |
2024-01-01 | 06:00:01 | Key_002_02_C | 8405 | kWh |
2024-01-01 | 06:00:01 | Key_010_C | 122 | kWh |
2024-01-01 | 06:00:08 | Key_101_01_C | 6591 | kWh |
2024-01-01 | 06:00:01 | Key_101_02_C | 6614 | kWh |
2024-01-01 | 06:00:01 | Key_102_1_C | 6441 | kWh |
2024-01-01 | 06:00:01 | Key_102_2_C | 6329 | kWh |
2024-02-01 | 06:00:02 | Key_001_C | 2557 | kWh |
2024-02-01 | 06:00:05 | Key_002_01_C | 9323 | kWh |
2024-02-01 | 06:00:10 | Key_002_02_C | 9405 | kWh |
2024-02-01 | 06:00:01 | Key_010_C | 222 | kWh |
2024-02-01 | 06:00:01 | Key_101_01_C | 7591 | kWh |
2024-02-01 | 06:00:01 | Key_101_02_C | 7614 | kWh |
2024-02-01 | 06:00:01 | Key_102_1_C | 5441 | kWh |
2024-02-01 | 06:00:01 | Key_102_2_C | 7329 | kWh |
What would be the best way, querying at any time/any day on February (and so on, thus January to December…), to get month differences between Id’s one-by-one, ignoring the seconds in the time ?
Day starts/ends at 06:00am for me (so January starts on Jan, 1st at 6:00am and ends on Feb, 1st at 6:00am).
Of course, I’ve values every hour (to be ignored).
I’m confused about using the lag()
function in this case.
2
Answers
Works fine with the following lines (without merging date/time fields) :
Regarding
LAG
function we can describe it asIf you use the following SQL, I believe you will be able to accomplish your goal.