Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7758303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:19:28+00:00 2026-06-01T13:19:28+00:00

I have a table with countries, years and amounts for each year. I’m trying

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:19:29+00:00Added an answer on June 1, 2026 at 1:19 pm

    Give this a try:

    SELECT 
         country as "Recipient", 
         SUM(if(project_year = 1991, usd_amount, 0)) AS "1991",
         SUM(if(project_year = 1992, usd_amount, 0)) AS "1992",
         SUM(if(project_year = 1993, usd_amount, 0)) AS "1993",
    FROM tb1
    GROUP BY country
    ORDER BY country
    

    PS: It makes no sense to order by project year as you’re already aggregating on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with countries, resorts and photos for resorts. Each photo may be
I have a table with a list of countries in it that I'm using
I am trying to write a query that would fetch the number of player
I have a two dimensional table with countries and years in Excel. eg. 1961
I have a table that represents a list of countries. I have another table
I simply have a table that contains a list of countries and their ISO
I have a table with different values for different countries, for example: id| country
I have 2 tables, 1 with countries, 1 with states. The states table has
I have table with all countries on three languages: English, Russian and Ukrainian. On
I have a table containing countries: id country ------------ 0 Monaco 1 Mongolia 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.