Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion problems/biggest-single-number/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 619. Biggest Single Number
## 619. Biggest Single Number (Easy)

<p>
Table <code>number</code> contains many numbers in column <b>num</b> including duplicated ones.<br>
Expand Down
22 changes: 21 additions & 1 deletion problems/students-report-by-geography/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
## 618. Students Report By Geography
## 618. Students Report By Geography (Hard)

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>

<pre>| name | continent |
|--------|-----------|
| Jack | America |
| Pascal | Europe |
| Xi | Asia |
| Jane | America |
</pre><p></p>

<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>

For the sample input, the output is:<p></p>
<pre>| America | Asia | Europe |
|---------|------|--------|
| Jack | Xi | Pascal |
| Jane | | |
</pre><p></p>

<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>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Write your MySQL query statement below

SELECT
America, Asia, Europe
FROM
(SELECT @as:=0, @am:=0, @eu:=0) t,
(SELECT
@as:=@as + 1 AS asid, name AS Asia
FROM
student
WHERE
continent = 'Asia'
ORDER BY Asia) AS t1
RIGHT JOIN
(SELECT
@am:=@am + 1 AS amid, name AS America
FROM
student
WHERE
continent = 'America'
ORDER BY America) AS t2 ON asid = amid
LEFT JOIN
(SELECT
@eu:=@eu + 1 AS euid, name AS Europe
FROM
student
WHERE
continent = 'Europe'
ORDER BY Europe) AS t3 ON amid = euid;

This file was deleted.