Biggest Single Number Problem
Description
LeetCode Problem 619.
Table my_numbers contains many numbers in column num including duplicated ones. Can you write a SQL query to find the biggest number, which only appears once.
1
2
3
4
5
6
7
8
9
10
11
12
+---+
|num|
+---+
| 8 |
| 8 |
| 3 |
| 3 |
| 1 |
| 4 |
| 5 |
| 6 |
+---+
For the sample data above, your query should return the following result:
1
2
3
4
5
+---+
|num|
+---+
| 6 |
+---+
Note: If there is no such number, just output null.
MySQL Solution
1
2
3
4
5
6
select max(num) as num
from
(select num
from my_numbers
group by num
having count(num) = 1) n
LeetCode Database - Easy
LeetCode 175
LeetCode 176
LeetCode 181
LeetCode 182
LeetCode 183
LeetCode 196
LeetCode 197
LeetCode 511
LeetCode 512
LeetCode 577
LeetCode 584
LeetCode 586
LeetCode 595
LeetCode 596
LeetCode 597
LeetCode 603
LeetCode 607
LeetCode 610
LeetCode 613
LeetCode 619
LeetCode 620
LeetCode 627
More LeetCode Database
MySQL Tutorials