Você precisa agrupar por extratos.
SELECT
SUM(amount)
FROM
transaction
GROUP BY
EXTRACT(MONTH FROM when),
EXTRACT(YEAR FROM when)
E se você precisar dessas colunas, então
SELECT
EXTRACT(MONTH FROM when) as month,
EXTRACT(YEAR FROM when) as year,
SUM(amount)
FROM
transaction
GROUP BY
month,
year
Claro que você pode anexar
ORDER BY
e use nomes curtos também:SELECT
EXTRACT(MONTH FROM when) as month,
EXTRACT(YEAR FROM when) as year,
SUM(amount)
FROM
transaction
GROUP BY
month,
year
ORDER BY
year DESC,
month DESC