-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path595_Big_Countries.sql
41 lines (31 loc) · 1.82 KB
/
595_Big_Countries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Source: https://leetcode.com/problems/big-countries/description/?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).
-- Write a solution to find the name, population, and area of the big countries.
-- Return the result table in any order.
------------------------------------------------------------------------------
-- SQL Schema
CREATE TABLE IF NOT EXISTS World (name varchar(255), continent varchar(255), area int, population int, gdp bigint)
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')
-- MS SQL Server Code
SELECT name, population, area
FROM World
WHERE area >= 3000000 OR population >= 25000000