MulaiMulai sekarang secara gratis

Aggregate before joining tables

You have a list of the following items:

  • African athletes participating in past Olympics
  • Country GDP per capita
  • Population by year

For simplification, the annual demographics (GDP and population) have been grouped into low, medium, and high categories. Your job is to compare each African country's GDP, population, and athlete count.

You want the final answer to have one row per country, per year. Because the athletes table is on a different grain (athlete-event) than the demographics_rank table (country-year), you will first aggregate the athletes table before joining it to the GDP and population data.

Latihan ini adalah bagian dari kursus

Improving Query Performance in PostgreSQL

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

-- Count the number of athletes by country
SELECT country_code
  , year
  , ___(___) AS no_athletes
FROM athletes
GROUP BY ___, ___;
Edit dan Jalankan Kode