diff --git a/problems/big-countries/big_countries.sql b/problems/big-countries/big_countries.sql index 2ff273519..bd4c7cee4 100644 --- a/problems/big-countries/big_countries.sql +++ b/problems/big-countries/big_countries.sql @@ -1,11 +1,11 @@ # Write your MySQL query statement below SELECT - `name`, - `population`, - `area` + `name`, + `population`, + `area` FROM - `World` + `World` WHERE - `area` > 3000000 - OR `population` > 25000000; + `area` > 3000000 + OR `population` > 25000000; diff --git a/problems/biggest-single-number/README.md b/problems/biggest-single-number/README.md index c8e545501..c4c5fb025 100644 --- a/problems/biggest-single-number/README.md +++ b/problems/biggest-single-number/README.md @@ -1,2 +1,25 @@ ## 619. Biggest Single Number +

+Table number contains many numbers in column num including duplicated ones.
+Can you write a SQL query to find the biggest number, which only appears once.
+

+
+---+
+|num|
++---+
+| 8 |
+| 8 |
+| 3 |
+| 3 |
+| 1 |
+| 4 |
+| 5 |
+| 6 | 
+
+For the sample data above, your query should return the following result: +
+---+
+|num|
++---+
+| 6 |
+
+Note:
If there is no such number, just output null.

diff --git a/problems/biggest-single-number/biggest_single_number.go b/problems/biggest-single-number/biggest_single_number.go deleted file mode 100644 index ac4661953..000000000 --- a/problems/biggest-single-number/biggest_single_number.go +++ /dev/null @@ -1 +0,0 @@ -package biggest_single_number diff --git a/problems/biggest-single-number/biggest_single_number.sql b/problems/biggest-single-number/biggest_single_number.sql new file mode 100644 index 000000000..5d2969ad5 --- /dev/null +++ b/problems/biggest-single-number/biggest_single_number.sql @@ -0,0 +1,17 @@ +# Write your MySQL query statement below + +# Method 1 +SELECT num +FROM + `number` +GROUP BY num +HAVING COUNT(num) = 1; + +# Method 2 +SELECT MAX(num) AS num +FROM + (SELECT num + FROM + number + GROUP BY num + HAVING COUNT(num) = 1) AS t; diff --git a/problems/biggest-single-number/biggest_single_number_test.go b/problems/biggest-single-number/biggest_single_number_test.go deleted file mode 100644 index ac4661953..000000000 --- a/problems/biggest-single-number/biggest_single_number_test.go +++ /dev/null @@ -1 +0,0 @@ -package biggest_single_number diff --git a/problems/duplicate-emails/duplicate_emails.sql b/problems/duplicate-emails/duplicate_emails.sql index b47029c84..c6d93cf24 100644 --- a/problems/duplicate-emails/duplicate_emails.sql +++ b/problems/duplicate-emails/duplicate_emails.sql @@ -1,10 +1,10 @@ # Write your MySQL query statement below SELECT - Email + Email FROM - Person + Person GROUP BY - Email + Email HAVING - count( 1 ) > 1; + count(1) > 1; diff --git a/problems/swap-salary/swap_salary.sql b/problems/swap-salary/swap_salary.sql index c23f919c4..3225d0023 100644 --- a/problems/swap-salary/swap_salary.sql +++ b/problems/swap-salary/swap_salary.sql @@ -1,8 +1,10 @@ # Write your MySQL query statement below +# Method 1 UPDATE salary SET sex = IF(sex = 'm', 'f', 'm'); +# Method 2 UPDATE salary SET sex = CASE sex WHEN 'm'