595. Big Countries
Problem Statement
Table: World
Column Name | Type |
---|---|
name | varchar |
continent | varchar |
area | int |
population | int |
gdp | big 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, thecontinent
to which it belongs, itsarea
, thepopulation
, and itsGDP
value.A country is big if it has an
area
of bigger thanor a population
of more than.
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
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 |
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 thename
,population
, andarea
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 theWorld
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