Skip to content
>_sqlbuddy

Big Countries

Find countries with a large area or population.

Start practice

Problem statement

Prompt

A country is big if its area is at least 3,000,000 km² OR its population is at least 25,000,000.

Given the world table below, write a query that returns the name, population, and area of every big country.

  • Thresholds are inclusive: area >= 3000000 and population >= 25000000.
  • The order of the result does not matter.

Example

namecontinentareapopulationgdp
ChinaAsia9600000144000000014300000
MonacoEurope2390007000
NauruOceania21108001300

Expected result:

namepopulationarea
China14400000009600000

Constraints

  • world.name is the primary key.

Tips

  • A simple WHERE area >= 3000000 OR population >= 25000000 is all it takes — no AND anywhere.

Schema

CREATE TABLE world (
    name       TEXT PRIMARY KEY,
    continent  TEXT NOT NULL,
    area       INTEGER NOT NULL,
    population INTEGER NOT NULL,
    gdp        INTEGER NOT NULL
);

Sample data

INSERT INTO world (name, continent, area, population, gdp) VALUES
  ('China',  'Asia',     9600000, 1440000000, 14300000),
  ('India',  'Asia',     3287263, 1400000000, 3170000),
  ('USA',    'N. America', 9833520, 332000000, 21000000),
  ('Monaco', 'Europe',   2,       39000,      7000),
  ('Nauru',  'Oceania',  21,      10800,      1300),
  ('Brazil', 'S. America', 8515767, 214000000, 1400000);

Additional hidden fixtures are applied during validation to test edge cases.

Solution

One correct approach — try solving it yourself in the practice editor first, then compare. There is usually more than one valid solution.

-- Reference: big by area or population, thresholds inclusive.
SELECT name, population, area
FROM world
WHERE area >= 3000000 OR population >= 25000000
ORDER BY name;

Key concepts

  • SELECT
  • WHERE OR
  • Column aliases

Related questions

Learn more