首页 > 数据库技术 > 详细

[LeetCode] 619. Biggest Single Number_Easy tag: SQL

时间:2018-08-29 00:52:56      阅读:190      评论:0      收藏: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

 

[LeetCode] 619. Biggest Single Number_Easy tag: SQL

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!