diff --git a/problems/biggest-single-number/README.md b/problems/biggest-single-number/README.md index c4c5fb025..ffc1ab6da 100644 --- a/problems/biggest-single-number/README.md +++ b/problems/biggest-single-number/README.md @@ -1,4 +1,4 @@ -## 619. Biggest Single Number +## 619. Biggest Single Number (Easy)
Table number
contains many numbers in column num including duplicated ones.
diff --git a/problems/students-report-by-geography/README.md b/problems/students-report-by-geography/README.md
index cf4648fe3..9a5989a4a 100644
--- a/problems/students-report-by-geography/README.md
+++ b/problems/students-report-by-geography/README.md
@@ -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 student
as below.
| name | continent | +|--------|-----------| +| Jack | America | +| Pascal | Europe | +| Xi | Asia | +| Jane | America | ++ + Pivot 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. + +For the sample input, the output is: +
| America | Asia | Europe | +|---------|------|--------| +| Jack | Xi | Pascal | +| Jane | | | ++ +Follow-up: If it is unknown which continent has the most students, can you write a query to generate the student report? diff --git a/problems/students-report-by-geography/students_report_by_geography.go b/problems/students-report-by-geography/students_report_by_geography.go deleted file mode 100644 index 7e0589efe..000000000 --- a/problems/students-report-by-geography/students_report_by_geography.go +++ /dev/null @@ -1 +0,0 @@ -package students_report_by_geography diff --git a/problems/students-report-by-geography/students_report_by_geography.sql b/problems/students-report-by-geography/students_report_by_geography.sql new file mode 100644 index 000000000..1c99109b1 --- /dev/null +++ b/problems/students-report-by-geography/students_report_by_geography.sql @@ -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; diff --git a/problems/students-report-by-geography/students_report_by_geography_test.go b/problems/students-report-by-geography/students_report_by_geography_test.go deleted file mode 100644 index 7e0589efe..000000000 --- a/problems/students-report-by-geography/students_report_by_geography_test.go +++ /dev/null @@ -1 +0,0 @@ -package students_report_by_geography