Show each month of 2026 as YYYY-MM with its total transaction amount, in chronological order. Table definitions (from…
SQLLevel: IntermediateGROUP BY and HAVING
Show each month of 2026 as YYYY-MM with its total transaction amount, in chronological order.
Table definitions (from the source exercise):
CREATE TABLE transactions(transaction_id INTEGER PRIMARY KEY, account_id INTEGER, transaction_date TEXT, amount REAL, merchant_category TEXT);
Hints
- Write an interleaving of two concurrent operations.
- Which observations does the isolation level permit, and what happens on a mid-operation failure?
Answer
Approach: DATE_FORMAT(transaction_date, '%Y-%m') makes the bucket; group and order by it.
SELECT DATE_FORMAT(transaction_date, '%Y-%m') AS txn_month,
SUM(amount) AS monthly_volume
FROM transactions
WHERE YEAR(transaction_date) = 2026
GROUP BY txn_month
ORDER BY txn_month;
The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT