LeetCode: Biggest Single Number

LeetCode: 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.

1
2
3
4
5
6
7
8
9
10
11
+---+
|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
+---+
|num|
+---+
| 6 |

Note:

  1. If there is no such number, just output null.
1
2
# Write your MySQL query statement below
select max(t.num) as num from (select num from number group by num having count(*) =1) t;