I've got a table with the following columns: timestamp, name and activePower. I wanted to compute power consumption based on that and add it to a Grafana line chart.
Right now, what I'm doing is a cumulative sum, like the following:
SELECT
"timestamp" as time,
"name", sum("activePower")
OVER(
PARTITION BY "name"
ORDER BY "timestamp"
) AS cumulative_sum
FROM main
Unfortunately, the intervals of timestamp are not regular, and I wanted to do something like a numerical integration (using trapezoidal rule or something).