Skip to content
Advertisement

How can I condition the time column?

There is a column representing 24 hours. Data comes in every 15 minutes. For example, at 10:15, the value is entered in the DateTime column of the 10H column. But… The client wants to set the standard for the day at 6:30 a.m. and set it to 6:30 the next day. If you look at the column below, should sum the value from column 6h.. Is there any way?

enter image description here

Advertisement

Answer

Consider breaking hour blocks into separate SELECT segments that add corresponding hour columns. Then, bind all parts together by UNION ALL. Finally, aggregate all hour blocks for final SUM.

Below sums all values between 2020-11-15 06:30 - 2020-11-16 06:30 (not including upper limit). Be sure to fill in the abbreviated ... for needed columns:

Of course, ideally your table maintains a normalized structure of long format with two columns for datetime and value. Then, querying is much easier:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement