Skip to content

595. Big Countries

Problem Statement

Table: World

Column NameType
namevarchar
continentvarchar
areaint
populationint
gdpbig int

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 bigger than 3,000,000 km2 or a population of more than 25,000,000.

Instructions

  • Write a solution to find the name, population, and area of the big countries.
  • Return the result table in any order.
  • The result form is the following example.

Example

Input: World table

namecontinentareapopulationgdp
AfghanistanAsia6522302550010020343000000
AlbaniaEurope28748283174112960000000
AlgeriaAfrica238174137100000188681000000
AndorraEurope468781153712000000
AngolaAfrica124670020609294100990000000

Output:

namepopulationarea
Afghanistan25500100652230
Algeria371000002381741

Submissions

sql
SELECT name, population, area
FROM World
WHERE area >= 3000000 OR population >= 25000000
python
import pandas as pd

def big_countries(world: pd.DataFrame) -> pd.DataFrame:
    return world.loc[(world['area'] >= 3000000) | (world['population'] >= 25000000), ['name', 'population', 'area']]

Explanations

PostgreSQL
Submitted by @noeyislearning
  • SELECT name, population, area: This part of the statement specifies the columns that you want to retrieve from the database. In this case, you're retrieving the name, population, and area columns.
  • FROM World: This part of the statement specifies the table from which you want to retrieve the data. In this case, you're retrieving data from the World table.
  • WHERE area >= 3000000 OR population >= 25000000: This is the condition for selecting the rows. Only rows that satisfy this condition will be included in the result. The condition here is that either the area should be greater than or equal to 3,000,000 or the population should be greater than or equal to 25,000,000. The OR operator ensures that if either of these conditions is met, the row will be included in the result.
Pandas
Submitted by @noeyislearning