Skip to content

Commit 2a7c65b

Browse files
author
Shuo
authored
Merge pull request #259 from openset/develop
Add: Biggest Single Number
2 parents 0deb756 + 09c1579 commit 2a7c65b

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Write your MySQL query statement below
22

33
SELECT
4-
`name`,
5-
`population`,
6-
`area`
4+
`name`,
5+
`population`,
6+
`area`
77
FROM
8-
`World`
8+
`World`
99
WHERE
10-
`area` > 3000000
11-
OR `population` > 25000000;
10+
`area` > 3000000
11+
OR `population` > 25000000;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
## 619. Biggest Single Number
22

3+
<p>
4+
Table <code>number</code> contains many numbers in column <b>num</b> including duplicated ones.<br>
5+
Can you write a SQL query to find the biggest number, which only appears once.<br>
6+
</p>
7+
<pre>+---+
8+
|num|
9+
+---+
10+
| 8 |
11+
| 8 |
12+
| 3 |
13+
| 3 |
14+
| 1 |
15+
| 4 |
16+
| 5 |
17+
| 6 |
18+
</pre>
19+
For the sample data above, your query should return the following result:
20+
<pre>+---+
21+
|num|
22+
+---+
23+
| 6 |
24+
</pre>
25+
<b>Note:</b><br> If there is no such number, just output <b>null</b>.<p></p>

problems/biggest-single-number/biggest_single_number.go

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Write your MySQL query statement below
2+
3+
# Method 1
4+
SELECT num
5+
FROM
6+
`number`
7+
GROUP BY num
8+
HAVING COUNT(num) = 1;
9+
10+
# Method 2
11+
SELECT MAX(num) AS num
12+
FROM
13+
(SELECT num
14+
FROM
15+
number
16+
GROUP BY num
17+
HAVING COUNT(num) = 1) AS t;

problems/biggest-single-number/biggest_single_number_test.go

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Write your MySQL query statement below
22

33
SELECT
4-
Email
4+
Email
55
FROM
6-
Person
6+
Person
77
GROUP BY
8-
Email
8+
Email
99
HAVING
10-
count( 1 ) > 1;
10+
count(1) > 1;

problems/swap-salary/swap_salary.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Write your MySQL query statement below
22

3+
# Method 1
34
UPDATE salary
45
SET sex = IF(sex = 'm', 'f', 'm');
56

7+
# Method 2
68
UPDATE salary
79
SET sex = CASE sex
810
WHEN 'm'

0 commit comments

Comments
 (0)