619. Biggest Single Number
Problem Statement
A single number is a number that appears only once. Find the largest single number. If there is no single number, report null.
Table Schema
Table: MyNumbers
+-------------+------+
| num | int |
+-------------+------+
May contain duplicates.
Examples
Example 1
Input Table:
MyNumbers table:
+-----+
| num |
+-----+
| 8 |
| 8 |
| 3 |
| 3 |
| 1 |
| 4 |
| 5 |
| 6 |
+-----+
Expected Output:
+-----+
| num |
+-----+
| 6 |
+-----+
SQL Solution
SELECT MAX(num) AS num
FROM (
SELECT num
FROM MyNumbers
GROUP BY num
HAVING COUNT(*) = 1
) t;
Problem Info
DifficultyEASY
Topics
subquerygroup-byhaving
Reference Links