Write a SQL query to find duplicate records and remove them while keeping the most recent row.
Treat rows in thermostat_events as duplicates when thermostat_id, event_type, reading_value, and recorded_at match. Keep the row with the latest created_at; if timestamps tie, keep the row with the greatest event_id.
event_id values of deleted rows.event_id descending.| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique identifier for the event record |
| thermostat_id | VARCHAR(30) | Identifier of the thermostat that produced the event |
| event_type | VARCHAR(30) | Type of thermostat event |
| reading_value | NUMERIC(8,2) | Numeric value recorded by the event |
| recorded_at | TIMESTAMP | Timestamp represented by the event |
| created_at | TIMESTAMP | Timestamp when the database row was created |