0

各カテゴリをグループ化し、各カテゴリの都市の総数を数えようとしています。

結果は次のようになります

+------------------------------+--------------+

| GNPPopRatioCategory | CountRecords |

+------------------------------+--------------+

| 1. Equal or greater than 2% | 145 |

| 2. Equal or greater than 1% | 104 |

| 3. Equal or greater than .5% | 566 |

| 4. Rest of country | 3264 |

これは私がこれまでに持っているものですが、それらをグループ化して各カテゴリの都市を数える方法がわかりません。インライン ビューを使用する方が効率的であるとのことですが、インライン ビューに移る前に、まずこの方法を理解したいと思います。助けてくれてありがとう。

Select Count(Country.GNP / City.Population) AS CountRecords,
(Select Case When CountRecords>= 2 THEN "1.Equal or greater than 2%"
When CountRecords>= 1 THEN "1.Equal or greater than 1%"
When CountRecords>= .5 THEN "1.Equal or greater than .5%"
ELSE "Rest of country" END) AS GNPPopRatioCategory
From City INNER JOIN Country ON City.Country=Country.Code 
Limit 20;

説明されている都市テーブル: ID、名前、国、地区、人口 国 説明されているテーブル: コード、名前、大陸、地域、SurfaceArea、IndepYear、Population、LifeExpectancy、GNP、LocalName、GovernmentForm、HeadOfState、Capital

4

1 に答える 1