Daily Energy Use From Cumulative Meter Registers With Resets

Last updated: November 29, 2026

Quick Overview

A table stores periodic readings of each meter's cumulative kWh register. Write SQL that returns daily consumption per meter, correctly handling register rollover at 1,000,000 kWh and meter replacements that reset the register.

Schneider Electric
Data Manipulation (SQL/Python)
Data Engineer
Schneider Electric
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


A table stores periodic readings of each meter's cumulative kWh register. Write SQL that returns daily consumption per meter, correctly handling register rollover at 1,000,000 kWh and meter replacements that reset the register.

Energy and sustainability reporting in Schneider software starts from raw cumulative registers, and the classic bug is a giant negative or positive spike when a register wraps or a meter is swapped. The interviewer checks window functions, explicit handling of the two kinds of drop, and how you attribute energy that spans midnight.

What the Interviewer Expects
  • Uses LAG partitioned by meter and ordered by time
  • Distinguishes rollover from reset with a stated rule
  • Excludes the first reading of each meter, which has no delta
  • Flags days with resets for data quality review
  • States how intervals crossing midnight are attributed
Key Topics to Cover
window functions
LAG
counter rollover
data quality
time series
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you prorate an interval from 22:00 to 02:00 across the two days?
  • How do you avoid treating a single bad low reading as a reset?
  • Readings arrive late. How would you make this an incremental daily job?
  • How would you store meter swap events so the logic is not a heuristic?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

meter_readings(meter_id, read_at, kwh_register). Register is monotonic except for (a) rollover: the dial wraps from 999,999.9 to 0, and (b) meter replacement or reset: the new meter starts near 0. I...

Approach
  1. LAG gives the previous register per meter.
  2. If the register increased, delta is the difference.
  3. If it dropped and the previous value was near the top (above 90% of max), it is a rollover: `c...

Submit Your Answer
Markdown supported

Related Questions