You inherited a spreadsheet and need to audit it for data quality issues before using it in analysis. Write a PostgreSQL query that flags each record as matched, missing_in_source, duplicate_in_sheet, or invalid_amount by comparing the spreadsheet rows to the source system and checking for duplicate sheet entries and non-positive amounts.
| Column | Type | Description |
|---|---|---|
| source_txn_idPK | INT | Primary key in the source system |
| account_code | VARCHAR(20) | Ledger account code |
| txn_date | DATE | Transaction date |
| amount | DECIMAL(12,2) | Source amount |
| Column | Type | Description |
|---|---|---|
| sheet_row_idPK | INT | Primary key for the inherited spreadsheet row |
| source_txn_id | INT | Source transaction id copied into the sheet |
| account_code | VARCHAR(20) | Account code in the sheet |
| txn_date | DATE | Transaction date in the sheet |
| amount | DECIMAL(12,2) | Amount entered in the sheet |