Big Countries
Find countries with a large area or population.
Start practiceProblem 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 >= 3000000andpopulation >= 25000000. - The order of the result does not matter.
Example
| name | continent | area | population | gdp |
|---|---|---|---|---|
| China | Asia | 9600000 | 1440000000 | 14300000 |
| Monaco | Europe | 2 | 39000 | 7000 |
| Nauru | Oceania | 21 | 10800 | 1300 |
Expected result:
| name | population | area |
|---|---|---|
| China | 1440000000 | 9600000 |
Constraints
world.nameis the primary key.
Tips
- A simple
WHERE area >= 3000000 OR population >= 25000000is all it takes — noANDanywhere.
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
- easyArticle Views IFind the authors who viewed their own articles at least once.
- easyFind Customer RefereeFind customers who are not referred by customer id 2.
- easyInvalid TweetsFind tweets whose content is longer than 15 characters.
- easyRecyclable and Low Fat ProductsFind the ids of products that are both low fat and recyclable.