SELECT meter_id, recorded_at, LAG(recorded_at) OVER (PARTITION BY meter_id ORDER BY recorded_at) AS prev FROM readings;SELECT meter_id, recorded_at, reading_kwh, AVG(reading_kwh) OVER (PARTITION BY meter_id ORDER BY recorded_at ROWS 96 PRECEDING) AS rolling_24h FROM readings;SELECT meter_id, reading_kwh FROM readings WHERE reading_kwh > (SELECT AVG(reading_kwh)+3*STDDEV(reading_kwh) FROM readings);SELECT DATE_FORMAT(recorded_at,'%Y-%m-%d') AS day, SUM(reading_kwh) FROM readings GROUP BY day;Apex Energy monitors 50,000 smart meters, each reporting a reading every 15 minutes β 1.2 billion rows and growing. The operations team needs gap detection (missing readings), anomaly detection (readings 3Ο above mean), rolling 24-hour averages, and a capacity forecasting query using linear regression in SQL.
No step-by-step guidance. Use the Reference window for command syntax only. You must determine the approach, the correct columns and order, and verify your own results.