SQL Snippet · Daily Energy Usage
A simple example showing how I might aggregate daily energy usage from a raw measurements table:
SELECT
DATE(reading_time) AS day,
SUM(wh_consumed) / 1000 AS kwh_total
FROM energy_readings
WHERE reading_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
GROUP BY DATE(reading_time)
ORDER BY day DESC;
The result can be visualized on the dashboard as a compact bar chart or integrated into an overview card.