What is wrong with this SQL statement?
Review the PostgreSQL query below and provide a corrected version. It is intended to report accounts whose settled, positive card transactions total at least 100.
SELECT a.account_id, a.account_name,
SUM(t.amount) AS settled_total,
COUNT(t.transaction_id) AS transaction_count
FROM accounts a
LEFT JOIN card_transactions t
ON a.account_id = t.account_id
WHERE t.status = 'settled'
AND t.amount > 0
GROUP BY a.account_id
HAVING settled_total >= 100
ORDER BY settled_total DESC;
account_id, account_name, settled_total, and transaction_count.account_id ascending.| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique account identifier |
| account_name | VARCHAR(100) | Account display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique card transaction identifier |
| account_id | INT | Account associated with the transaction |
| status | VARCHAR(20) | Transaction processing status |
| amount | NUMERIC(12,2) | Transaction amount |