I have this query running fine in the FlightSQL plugin for Grafana which shows the electricity demand by hour (the data is collected every hour and the value represents the electricity demand for that hour):
SELECT * FROM "ElectricPowerOperations"
WHERE "type" IN ('Demand')
AND "region" IN ('Texas') AND $__timeRange(time)
How can I modify the above query to produce a graph that aggregates the data by week and another graph that aggregates by month?
In Flux, I would do this to get the data by week:
|> aggregateWindow(every: 1w, offset: -3d, fn: sum) // sums the 7 days of each week to get the total used per week, and use -3d as the offset to move the weekly aggregate to start on a Monday
and this to get the data by month:
|> aggregateWindow(every: 1mo, fn: sum) // sums the total used per month
SELECT date_Bin(INTERVAL '1 month', time, TIMESTAMP '1970-01-01 00:00:00Z') AS time, sum("value") AS sum_value, region
FROM "ElectricPowerOperations" WHERE "type" IN ('Demand') AND "region" IN (${region}) AND $__timeRange(time) GROUP BY 1, region
ORDER BY time ASC