Monthly Deposits in 2025
Return month (as text like '2025-03') and deposited_cents (the sum of deposit amounts) for each month of 2025 that has deposits. Only transactions with kind = 'deposit' count. Sort by month.
Hint 1
SUBSTR(txn_date, 1, 7) or STRFTIME('%Y-%m', txn_date) gives the year and month.
Hint 2
Group by the same expression you select.
Reference solution
SELECT STRFTIME('%Y-%m', txn_date) AS month,
SUM(amount_cents) AS deposited_cents
FROM transactions
WHERE kind = 'deposit'
AND txn_date BETWEEN '2025-01-01' AND '2025-12-31'
GROUP BY STRFTIME('%Y-%m', txn_date)
ORDER BY month;
Reports by period group on a year-month value, not on the month number alone: January 2024 and January 2025 are different groups. Filter the year in WHERE (cheap, and it removes rows early) and group on '%Y-%m'. This pattern (filter, derive a period, group, aggregate) is the skeleton of most business reports.
Another way. Cut the first seven characters of the ISO date, and group by the alias (SQLite allows this).
SELECT SUBSTR(txn_date, 1, 7) AS month,
SUM(amount_cents) AS deposited_cents
FROM transactions
WHERE kind = 'deposit'
AND txn_date >= '2025-01-01' AND txn_date < '2026-01-01'
GROUP BY month
ORDER BY month;