I have a table with countries, years and amounts for each year. I’m trying to write a query that will sum the total amounts for a given year and give it to me as a column.
For example, to have an output that looks like:
Country 1991 1992 1993
France 25 12 38
I tried a query like this, but to no avail:
SELECT
country as "Recipient",
SUM(usd_amount) AS "1991" WHEN project_year = 1991,
SUM(usd_amount) AS "1992" WHEN project_year = 1992,
SUM(usd_amount) AS "1993" WHEN project_year = 1993
FROM tb1
GROUP BY project_year, country
order by country, project_year
Any Suggestions?
Thanks!
Chris
Give this a try:
PS: It makes no sense to order by project year as you’re already aggregating on it.