Quick Overview

Write a SQL query that lists the name, population and area of every country that meets an area threshold or a population threshold, where a value equal to the threshold passes. It tests WHERE filters with OR, inclusive comparisons and how NULL values behave in a boolean condition.

Find big countries by area or population threshold

Company: Adobe

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

A country is big if its area is at least 3,000,000 km² or its population is at least 25,000,000. Write a query that returns the `name`, `population` and `area` of every big country in the `World` table, ordered by `name`. ```hint Check the thresholds Count the zeros in each threshold, and check what should happen to a value exactly equal to one. ``` ### Input Table(s) `World` | Column | Type | Meaning | |---|---|---| | name | VARCHAR(255) | Country name, primary key | | continent | VARCHAR(255) | Continent the country is on | | area | INT | Area in square kilometers | | population | BIGINT | Number of inhabitants | | gdp | BIGINT | Gross domestic product. Not needed for this query. | Keys: `name` is the primary key, so each country appears in exactly one row. ### Output Contract | Column | Type | Meaning | |---|---|---| | name | VARCHAR | Country name | | population | BIGINT | Population as stored | | area | INT | Area as stored | - Columns in this order: `name`, `population`, `area`. - One row per big country. - Order by `name` ascending. `name` is the primary key, so the order is unique. - No rounding or unit conversion. ### Example `World` | name | continent | area | population | gdp | |---|---|---|---|---| | Arland | Europe | 3000000 | 1200000 | 45000000000 | | Borovia | Asia | 450000 | 25000000 | 310000000000 | | Calderra | Africa | 2999999 | 24999999 | 98000000000 | | Dunmore | Oceania | 7600000 | 26000000 | 1500000000000 | | Estavia | Europe | 120000 | 9000000 | 210000000000 | Expected result: | name | population | area | |---|---|---| | Arland | 1200000 | 3000000 | | Borovia | 25000000 | 450000 | | Dunmore | 26000000 | 7600000 | Arland qualifies on area alone with a value exactly at the threshold, and Borovia qualifies on population alone at exactly 25,000,000. Dunmore passes both tests and still appears once. Calderra misses each threshold by one, and Estavia misses both. ### Constraints and Clarifications - `World` has at most 500 rows. - `area` and `population` are non-negative integers. - Both thresholds are inclusive: a value equal to the threshold passes. - Meeting either threshold is enough. A country that meets both appears once. - The columns have no NOT NULL constraint. If one of `area` or `population` is NULL, judge the country on the other value alone. A country with both values NULL is not big.

Overview: Write a SQL query that lists the name, population and area of every country that meets an area threshold or a population threshold, where a value equal to the threshold passes. It tests WHERE filters with OR, inclusive comparisons and how NULL values behave in a boolean condition.

A country is big if its area is at least 3,000,000 km² or its population is at least 25,000,000. Write a query that returns the `name`, `population` and `area` of every big country in the `world` table, ordered by `name` ascending. Table `world` has these columns: - `name` (VARCHAR(255)): country name, primary key, so each country appears in exactly one row. - `continent` (VARCHAR(255)): continent the country is on. - `area` (INTEGER): area in square kilometers. - `population` (BIGINT): number of inhabitants. - `gdp` (BIGINT): gross domestic product. Not needed for this query. Rules: - Both thresholds are inclusive: a value equal to the threshold passes. - Meeting either threshold is enough. A country that meets both appears once. - `area` and `population` are non-negative integers, but the columns have no NOT NULL constraint. If one of `area` or `population` is NULL, judge the country on the other value alone. A country with both values NULL is not big. - `world` has at most 500 rows. Output: the columns `name`, `population`, `area` in this order, with values as stored (no rounding or unit conversion), one row per big country, ordered by `name` ascending. `name` is the primary key, so the order is unique.

Tables

world(name VARCHAR(255), continent VARCHAR(255), area INTEGER, population BIGINT, gdp BIGINT)

Hints

  1. Count the zeros in each threshold, and check what should happen to a value exactly equal to one.
  2. Work out what a comparison against a NULL value returns, and check that a country with one missing value can still qualify on the other value.
AdobeData ScientisteasyData Manipulation (SQL/Python)

Big Countries

A country is big if its area is at least 3,000,000 km² or its population is at least 25,000,000. Write a query that returns the name, population and area of every big country in the world table, ordered by name ascending.

Table world has these columns:

  • name (VARCHAR(255)): country name, primary key, so each country appears in exactly one row.
  • continent (VARCHAR(255)): continent the country is on.
  • area (INTEGER): area in square kilometers.
  • population (BIGINT): number of inhabitants.
  • gdp (BIGINT): gross domestic product. Not needed for this query.

Rules:

  • Both thresholds are inclusive: a value equal to the threshold passes.
  • Meeting either threshold is enough. A country that meets both appears once.
  • area and population are non-negative integers, but the columns have no NOT NULL constraint. If one of area or population is NULL, judge the country on the other value alone. A country with both values NULL is not big.
  • world has at most 500 rows.

Output: the columns name, population, area in this order, with values as stored (no rounding or unit conversion), one row per big country, ordered by name ascending. name is the primary key, so the order is unique.

Expected Output

Tables

world
world
ColumnType
nameVARCHAR(255)
continentVARCHAR(255)
areaINTEGER
populationBIGINT
gdpBIGINT

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Language
Run code to see results here.

Browse More Questions