Welcome to Subscribe On Youtube

Formatted question description: https://leetcode.ca/all/619.html

619. Biggest Single Number

Level

Easy

Description

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.

+---+
|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.

Solution

Use select max(num) to select the biggest number. To select the biggest number that only appears once, use having count(num) = 1 as a condition.

# Write your MySQL query statement below
select max(num) as num
from (select num from my_numbers
      group by num
      having count(num) = 1) as t;

All Problems

All Solutions