Vous devez regrouper par extraits.
SELECT
SUM(amount)
FROM
transaction
GROUP BY
EXTRACT(MONTH FROM when),
EXTRACT(YEAR FROM when)
Et si vous avez besoin de ces colonnes, alors
SELECT
EXTRACT(MONTH FROM when) as month,
EXTRACT(YEAR FROM when) as year,
SUM(amount)
FROM
transaction
GROUP BY
month,
year
Bien sûr, vous pouvez ajouter ORDER BY
et utilisez aussi des noms courts :
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