Your question is Rolling Averages and Anomaly Flags. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Amazon Services Operations Managers monitor hourly package throughput across fulfillment facilities. Write a PostgreSQL query that calculates a three-reading rolling average and identifies unusually high or low throughput.
ANOMALY when it differs from the rolling average by more than 20%. Label rows with fewer than three non-null readings in the frame as INSUFFICIENT_DATA; otherwise label them NORMAL.| Column | Type | Description |
|---|---|---|
| facility_idPK | INT | Amazon fulfillment facility identifier |
| facility_name | VARCHAR(100) | Facility code used by operations teams |
| region | VARCHAR(50) | Geographic operating region |
| Column | Type | Description |
|---|---|---|
| log_idPK | INT | Unique throughput log identifier |
| facility_id | INT | Facility associated with the measurement |
| logged_hour | TIMESTAMP | Start time of the hourly measurement |
| throughput_units | INT | Packages processed during the hour |