Domanda

Hello I am trying to complete the following:

From the City table select the Name and from the country table select the name. I want to create a calculated field 'GNPOverPop' that calculates GNP/City Population and format that field 6 decimal places. After that I would like to create another calculated field that determines the following:

If the city has a population that is:

  1. greater than or equal to 10% of the countries population then prints '10% or more' into the calculated field value

  2. greater than or equal to 5% of the countries population then prints '5% or more' into the calculated field value

  3. greater than or equal to 1% of the countries population then prints '1% or more' into the calculated field value

  4. not in one of the above categories then prints 'Less than 1%' into the calculated field value

Right now I have the following query I am working on however I am running into a roadblock trying to figure out the IF/Case portion.

Select City.Name, Country.Name, 
       Format(Country.GNP / City.Population,6) AS GNPOverPOP
From City, Country
Limit 200;

The values should look like this:

| Name       | Name           | GNPOverPop  | PopGNPDesc  |
___________________________________________________________
| Charleston | United States  | 95.558200   | 10% or more |
| Carson     | United States  | 95.530312   | 10% or more |
| Odessa     | United States  | 95.312063   | 10% or more |
| Elgin      | United States  | 95.189469   | 10% or more |
| Kenosha    | United States  | 95.147965   | 10% or more |

Thanks for any help you can provide

È stato utile?

Soluzione

This is for the conditional part

SELECT ...
    (CASE WHEN GNPOverPOP >= 10 THEN "10% or more"
          WHEN GNPOverPOP >= 5 THEN "5% or more"
          WHEN GNPOverPOP >= 1 THEN "1% or more"
          ELSE "Less than 1%"
    END) AS PopGNPDesc
FROM ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top