Skip to content

Commit 96ab0ac

Browse files
author
Shuo
authored
Merge pull request #260 from openset/develop
Add: Students Report By Geography
2 parents 2a7c65b + 6d7dbb2 commit 96ab0ac

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

problems/biggest-single-number/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 619. Biggest Single Number
1+
## 619. Biggest Single Number (Easy)
22

33
<p>
44
Table <code>number</code> contains many numbers in column <b>num</b> including duplicated ones.<br>
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
## 618. Students Report By Geography
1+
## 618. Students Report By Geography (Hard)
22

3+
A U.S graduate school has students from Asia, Europe and America. The students' location information are stored in table <code>student</code> as below.<p></p>
4+
5+
<pre>| name | continent |
6+
|--------|-----------|
7+
| Jack | America |
8+
| Pascal | Europe |
9+
| Xi | Asia |
10+
| Jane | America |
11+
</pre><p></p>
12+
13+
<a href="https://en.wikipedia.org/wiki/Pivot_table"> Pivot</a> the continent column in this table so that each name is sorted alphabetically and displayed underneath its corresponding continent. The output headers should be America, Asia and Europe respectively. It is guaranteed that the student number from America is no less than either Asia or Europe.<p></p>
14+
15+
For the sample input, the output is:<p></p>
16+
<pre>| America | Asia | Europe |
17+
|---------|------|--------|
18+
| Jack | Xi | Pascal |
19+
| Jane | | |
20+
</pre><p></p>
21+
22+
<b>Follow-up:</b> If it is unknown which continent has the most students, can you write a query to generate the student report?<p></p>

problems/students-report-by-geography/students_report_by_geography.go

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Write your MySQL query statement below
2+
3+
SELECT
4+
America, Asia, Europe
5+
FROM
6+
(SELECT @as:=0, @am:=0, @eu:=0) t,
7+
(SELECT
8+
@as:=@as + 1 AS asid, name AS Asia
9+
FROM
10+
student
11+
WHERE
12+
continent = 'Asia'
13+
ORDER BY Asia) AS t1
14+
RIGHT JOIN
15+
(SELECT
16+
@am:=@am + 1 AS amid, name AS America
17+
FROM
18+
student
19+
WHERE
20+
continent = 'America'
21+
ORDER BY America) AS t2 ON asid = amid
22+
LEFT JOIN
23+
(SELECT
24+
@eu:=@eu + 1 AS euid, name AS Europe
25+
FROM
26+
student
27+
WHERE
28+
continent = 'Europe'
29+
ORDER BY Europe) AS t3 ON amid = euid;

problems/students-report-by-geography/students_report_by_geography_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)