Write a SQL query to compare partner-reported counts with internal counts and flag mismatches.
Use the provided partner reports and internal event records. Count only internal events whose status is counted; treat missing counts as zero. Include dates present on either side.
partner_id, partner_name, comparison_date, reported_count, internal_count, count_difference, mismatch_flag, and previous_mismatch.count_difference is reported minus internal. Sort by partner_id, then comparison_date.| Column | Type | Description |
|---|---|---|
| partner_idPK | VARCHAR(20) | Unique partner identifier |
| partner_name | VARCHAR(100) | Partner display name |
| Column | Type | Description |
|---|---|---|
| report_idPK | INT | Unique report record identifier |
| partner_id | VARCHAR(20) | Partner that submitted the report |
| report_date | DATE | Date represented by the report |
| reported_count | INT | Count submitted by the partner |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique internal event identifier |
| partner_id | VARCHAR(20) | Partner associated with the event |
| event_date | DATE | Date on which the event occurred |
| event_status | VARCHAR(20) | Processing status of the event |