1
我有一張表,每年的國家,年份和金額。我試圖編寫一個查詢,將總和給定年份的總金額,並將其作爲列給我。選擇給定年份的金額
例如,有一個輸出,看起來像:
Country 1991 1992 1993
France 25 12 38
我想這樣的查詢,但無濟於事:
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
有什麼建議? 謝謝! 克里斯
共享存儲在表中的數據的exapmle。 – 2012-04-09 06:18:23