码迷,mamicode.com
首页 > 数据库 > 详细

[LeetCode] 619. Biggest Single Number_Easy tag: SQL

时间:2018-08-29 01:06:55      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:from   contains   put   note   ble   query   weight   sele   tab   

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

 

[LeetCode] 619. Biggest Single Number_Easy tag: SQL

标签:from   contains   put   note   ble   query   weight   sele   tab   

原文地址:https://www.cnblogs.com/Johnsonxiong/p/9551591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!