Your question is Audit CRM Data Integrity by Team. Start with the requirements and the three 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.
You are given CRM records entered by multiple teams. Write a PostgreSQL query that returns each team’s total records, the number of records with data integrity issues, and the issue rate. Treat a record as problematic if it has a missing owner, a missing account, or a status that is not one of new, working, qualified, or closed.
| Column | Type | Description |
|---|---|---|
| record_id | INT | Primary key for the CRM record |
| team_id | INT | Team that entered or owns the record |
| owner_id | INT | Assigned user; may be NULL when ownership is missing |
| account_id | INT | Linked account; may be NULL when the record is incomplete |
| status | VARCHAR(20) | Current CRM status value |
| created_at | DATE | Date the record was created |
| Column | Type | Description |
|---|---|---|
| team_id | INT | Primary key for the team |
| team_name | VARCHAR(100) | Team name |
| Column | Type | Description |
|---|---|---|
| user_id | INT | Primary key for the user |
| user_name | VARCHAR(100) | User name |