0% found this document useful (0 votes)
27 views3 pages

Big Countries

The document describes the 'Big Countries' problem from LeetCode, where a country is classified as big if it has an area of at least 3 million km² or a population of at least 25 million. It provides the structure of the 'World' table and an SQL query to retrieve the names, populations, and areas of these big countries. The output format is specified, showing the expected results based on the given conditions.

Uploaded by

rk0550032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Big Countries

The document describes the 'Big Countries' problem from LeetCode, where a country is classified as big if it has an area of at least 3 million km² or a population of at least 25 million. It provides the structure of the 'World' table and an SQL query to retrieve the names, populations, and areas of these big countries. The output format is specified, showing the expected results based on the given conditions.

Uploaded by

rk0550032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

595.

Big Countries

Source:https://leetcode.com/problems/big-countries/?envType=study-
plan-v2&envId=top-sql-50

Table: World

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

Name is the primary key (column with unique values) 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 km2), or


it has a population of at least twenty-five million (i.e., 25000000).

The result format is in the following example.

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 |
+-------------+------------+---------+

Q) Write a solution to find the name, population, and area of the big
countries. Return the result table in any order.

Ans:

select name, population, area


from World
where area >= 3000000 or population >= 25000000;

Explanation:

1. SELECT name, population, area

●​ You want the output to include:​

○​ The country’s name​


○​ Its population​

○​ Its area​

2. FROM World

●​ You’re querying data from the table named World.​

3. WHERE area >= 3000000 OR population >= 25000000

This is the filtering condition. It includes countries that satisfy at least one of
the two conditions:

✔ Condition A: area >= 3000000

●​ This selects countries with a large land area, at least 3 million square
kilometers.​

✔ Condition B: population >= 25000000

●​ This selects countries with a large population, at least 25 million people.​

✔ OR Operator

●​ Countries will be included if they satisfy either condition.

-​ AMIT KUMAR

You might also like