#470 SQL Queries for Countries, Population, and GDP

Companies:
Sberbank
Themes:
SQLJoinsAggregationSubqueriesPractice

The following tables are given:

CREATE TABLE country (
    id          SERIAL
    name        VARCHAR(100)
    continent   VARCHAR(50)
    population  INT
);

CREATE TABLE gdp (
    id
    country_id  INT
    year        INT
    value       INT
);

Required:

  1. Return continents and the total population of each;
  2. Return continents and the total population of each where the population exceeds one billion;
  3. Return the country name and GDP per capita;
  4. Explain errors involving NULL and 0;
  5. There are 200 rows in the country table and 180 in gdp. How many rows will the query return? Explain using set theory;
  6. Return the continent, country name, and population. Show only the largest country by population on each continent;
  7. The same as item 6, but return the top 3 countries.

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in