代码改变世界

[LeetCode] 619. Biggest Single Number_Easy tag: SQL

2018-08-28 23:13  Johnson_强生仔仔  阅读(291)  评论(0编辑  收藏  举报

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.

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

Code

SELECT MAX(num) as num FROM (SELECT num FROM number GROUP BY num HAVING COUNT(num) = 1) AS t
# note : have to has AS t