Skip to content

Commit b0f5c81

Browse files
authored
Added tasks 595, 596.
1 parent 677a2f5 commit b0f5c81

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
595\. Big Countries
2+
3+
Easy
4+
5+
SQL Schema
6+
7+
Table: `World`
8+
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| name | varchar |
13+
| continent | varchar |
14+
| area | int |
15+
| population | int |
16+
| gdp | int |
17+
+-------------+---------+
18+
name is the primary key column for this table.
19+
Each row of this table gives information about the name of a country, the continent to which it belongs,
20+
its area, the population, and its GDP value.
21+
22+
A country is **big** if:
23+
24+
* it has an area of at least three million (i.e., <code>3000000 km<sup>2</sup></code>), or
25+
* it has a population of at least twenty-five million (i.e., `25000000`).
26+
27+
Write an SQL query to report the name, population, and area of the **big countries**.
28+
29+
Return the result table in **any order**.
30+
31+
The query result format is in the following example.
32+
33+
**Example 1:**
34+
35+
**Input:**
36+
37+
World table:
38+
+-------------+-----------+---------+------------+--------------+
39+
| name | continent | area | population | gdp |
40+
+-------------+-----------+---------+------------+--------------+
41+
| Afghanistan | Asia | 652230 | 25500100 | 20343000000 |
42+
| Albania | Europe | 28748 | 2831741 | 12960000000 |
43+
| Algeria | Africa | 2381741 | 37100000 | 188681000000 |
44+
| Andorra | Europe | 468 | 78115 | 3712000000 |
45+
| Angola | Africa | 1246700 | 20609294 | 100990000000 |
46+
+-------------+-----------+---------+------------+--------------+
47+
48+
**Output:**
49+
50+
+-------------+------------+---------+
51+
| name | population | area |
52+
+-------------+------------+---------+
53+
| Afghanistan | 25500100 | 652230 |
54+
| Algeria | 37100000 | 2381741 |
55+
+-------------+------------+---------+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write your MySQL query statement below
2+
# #Easy #Database
3+
select name, population, area
4+
from world
5+
where area >= 3000000
6+
or population >= 25000000
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
596\. Classes More Than 5 Students
2+
3+
Easy
4+
5+
SQL Schema
6+
7+
Table: `Courses`
8+
9+
+-------------+---------+
10+
| Column Name | Type |
11+
+-------------+---------+
12+
| student | varchar |
13+
| class | varchar |
14+
+-------------+---------+
15+
(student, class) is the primary key column for this table.
16+
Each row of this table indicates the name of a student and the class in which they are enrolled.
17+
18+
Write an SQL query to report all the classes that have **at least five students**.
19+
20+
Return the result table in **any order**.
21+
22+
The query result format is in the following example.
23+
24+
**Example 1:**
25+
26+
**Input:**
27+
28+
Courses table:
29+
+---------+----------+
30+
| student | class |
31+
+---------+----------+
32+
| A | Math |
33+
| B | English |
34+
| C | Math |
35+
| D | Biology |
36+
| E | Math |
37+
| F | Computer |
38+
| G | Math |
39+
| H | Math |
40+
| I | Math |
41+
+---------+----------+
42+
43+
**Output:**
44+
45+
+---------+
46+
| class |
47+
+---------+
48+
| Math |
49+
+---------+
50+
51+
**Explanation:**
52+
53+
- Math has 6 students, so we include it.
54+
- English has 1 student, so we do not include it.
55+
- Biology has 1 student, so we do not include it.
56+
- Computer has 1 student, so we do not include it.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Write your MySQL query statement below
2+
# #Easy #Database
3+
select class
4+
from Courses
5+
group by class
6+
having count(student) >= 5

0 commit comments

Comments
 (0)