Skip to content

Latest commit

 

History

History
101 lines (83 loc) · 2.84 KB

595. Big Countries.md

File metadata and controls

101 lines (83 loc) · 2.84 KB

1. Description

SQL Schema:
CREATE TABLE IF NOT EXISTS World (
    name varchar(255),
    continent varchar(255),
    area int,
    population int,
    gdp int
) TRUNCATE TABLE World

INSERT INTO
    World (name, continent, area, population, gdp)
VALUES
    ('Afghanistan', 'Asia', '652230', '25500100', '20343000000')
INSERT INTO
    World (name, continent, area, population, gdp)
VALUES
    ('Albania', 'Europe', '28748', '2831741', '12960000000')
INSERT INTO
    World (name, continent, area, population, gdp)
VALUES
    ('Algeria', 'Africa', '2381741', '37100000', '188681000000')
INSERT INTO
    World (name, continent, area, population, gdp)
VALUES
    ('Andorra', 'Europe', '468', '78115', '3712000000')
INSERT INTO
    World (name, continent, area, population, gdp)
VALUES
    ('Angola', 'Africa', '1246700', '20609294', '100990000000')

Table: World

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| name        | varchar |
| continent   | varchar |
| area        | int     |
| population  | int     |
| gdp         | int     |
+-------------+---------+

name is the primary key column for this table.
Each row of this table gives information about the name of a country, the continent to which it belongs, its area, the population, and its GDP value.

A country is big if:

  • it has an area of at least three million (i.e., 3000000 km^2), or
  • it has a population of at least twenty-five million (i.e., 25000000).

Write an SQL query to report the name, population, and area of the big countries.

Return the result table in any order.

Example 1:

Input:
World table:
+-------------+-----------+---------+------------+--------------+
| name        | continent | area    | population | gdp          |
+-------------+-----------+---------+------------+--------------+
| Afghanistan | Asia      | 652230  | 25500100   | 20343000000  |
| Albania     | Europe    | 28748   | 2831741    | 12960000000  |
| Algeria     | Africa    | 2381741 | 37100000   | 188681000000 |
| Andorra     | Europe    | 468     | 78115      | 3712000000   |
| Angola      | Africa    | 1246700 | 20609294   | 100990000000 |
+-------------+-----------+---------+------------+--------------+
Output:
+-------------+------------+---------+
| name        | population | area    |
+-------------+------------+---------+
| Afghanistan | 25500100   | 652230  |
| Algeria     | 37100000   | 2381741 |
+-------------+------------+---------+

2. Solutions

Solution 1: Language: SQL

  • Monday, 28 November, 2022
  • Runtime: 417 ms, faster than 47.32% of MySQL online submissions for Big Countries.
SELECT name, population, area
FROM World
WHERE (area >= 3000000 OR population >= 25000000);