You’re on the data engineering team at a fintech payments processor that settles card and bank-transfer transactions for thousands of merchants. Operations agents can create manual_entries to correct partner file issues (e.g., missing references, late-arriving settlement files). Because these entries can impact reconciliation and regulatory reporting, the risk team runs a daily audit to detect data integrity problems.
In the last week, the audit dashboard showed a spike in duplicate partner references and broken links to the canonical transactions table. Your task is to generate a daily integrity report for the last 7 days of data, anchored to the most recent manual_entries.created_at date in the dataset (not CURRENT_DATE, to keep results deterministic for backfills).
Write a SQL query that produces daily integrity metrics for manual entries in the last 7 days.
>= (max(created_at)::date - 6 days) where max(created_at) is taken from manual_entries.entry_date (UTC date of manual_entries.created_at) return:
total_entries: number of manual entries created that dayduplicate_partner_refs: number of entries whose (partner_id, partner_ref) appears more than once within the 7-day windowconflicting_amount_or_currency: number of entries that are duplicates and where the duplicate group has more than one distinct amount or more than one distinct currencymissing_linked_txn: number of entries where linked_transaction_id is not null but does not exist in transactionsentry_date ascending.manual_entries| column | type | description |
|---|---|---|
| entry_id | BIGINT | Primary key |
| partner_id | INT | Partner identifier |
| partner_ref | VARCHAR(64) | Reference from partner file / operator entry |
| amount | DECIMAL(12,2) | Entered amount |
| currency | CHAR(3) | ISO currency code |
| linked_transaction_id | BIGINT | Nullable reference to transactions.transaction_id (not always enforced) |
| created_by | VARCHAR(64) | Operator username |
| created_at | TIMESTAMP | Entry creation timestamp (UTC) |
transactions| column | type | description |
|---|---|---|
| transaction_id | BIGINT | Primary key |
| partner_id | INT | Partner identifier |
| amount | DECIMAL(12,2) | Settled amount |
| currency | CHAR(3) | ISO currency code |
| status | VARCHAR(24) | Transaction status (e.g., SETTLED, DECLINED) |
| created_at | TIMESTAMP | Transaction creation timestamp (UTC) |