619.单一数字 是在 MyNumbers 表中只出现一次的数字。 找出最大的 单一数字 。如果不存在 单一数字 ,则返回 null
题目链接:
https://leetcode.cn/problems/biggest-single-number/
建表插入数据:
sql
Create table If Not Exists MyNumbers (num int)
Truncate table MyNumbers
insert into MyNumbers (num) values ('8')
insert into MyNumbers (num) values ('8')
insert into MyNumbers (num) values ('3')
insert into MyNumbers (num) values ('3')
insert into MyNumbers (num) values ('1')
insert into MyNumbers (num) values ('4')
insert into MyNumbers (num) values ('5')
insert into MyNumbers (num) values ('6')
思路分析:
查找最大的单一数字,先count()计算出每个数字的出现的次数;再求出max()最大出现一次的数字即为所求
画图分析:
代码实现:
sql
with t1 as ( select num,count(*) over (partition by num) count
from mynumbers )
select max(num) as num from t1 where count=1;