How do you ensure data quality and integrity when building a new business dashboard?
Using the provided accounts and trades tables, write a PostgreSQL query that produces an account-level quality report for January 2026. Treat a trade as invalid when its symbol is missing, quantity or price is not positive, or its status is not EXECUTED. Accounts without January trades must remain in the report.
account_id, customer_segment, trade_count, invalid_trade_count, valid_trade_notional, and quality_status.invalid_trade_count descending, then account_id ascending.| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique brokerage account identifier |
| customer_segment | VARCHAR(30) | Business segment assigned to the account |
| Column | Type | Description |
|---|---|---|
| trade_idPK | INT | Unique trade identifier |
| account_id | INT | Account that submitted the trade |
| symbol | VARCHAR(12) | Security ticker symbol |
| side | VARCHAR(10) | Trade direction |
| quantity | NUMERIC(12,2) | Number of shares or units |
| price | NUMERIC(14,2) | Execution price per unit |
| executed_at | DATE | Trade execution date |
| status | VARCHAR(20) | Trade processing status |