Your question is SQL: Monthly Complaints With MoM. 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.
Write a SQL query to calculate monthly service complaints by site, including the month-over-month change in complaints.
Use the service complaints data across all months represented by complaint dates. Include every site for every month in that range, including months with zero complaints. The first month for each site should have a NULL prior-month value and NULL change.
site_name, month, complaint_count, previous_month_complaints, mom_changesite_name, then chronological month| Column | Type | Description |
|---|---|---|
| site_idPK | INT | Unique facility identifier |
| site_name | VARCHAR(100) | Facility name |
| region | VARCHAR(50) | Operational region |
| Column | Type | Description |
|---|---|---|
| complaint_idPK | INT | Unique complaint identifier |
| site_id | INT | Site associated with the complaint |
| complaint_date | DATE | Date the complaint was received |
| category | VARCHAR(80) | Complaint category |