select *,
row_number() over(partition by email order by id asc) as 'rank'
from Person
可以显然得出 临时表中rank >1 的都是重复的,嵌套一层查id出来
sql复制代码
select id from (
select *,
row_number() over(partition by email order by id asc) as 'rank' from Person
) temp where temp.rank = 1
执行删除语句
sql复制代码
delete from Person where id not in (
select id from (
select *,row_number() over(partition by email order by id asc) as 'rank' from Person
) temp where temp.rank = 1
)
with t1 as(
select requester_id as 'id' from RequestAccepted
union all
select accepter_id as 'id' from RequestAccepted
),
t2 as(
select id,count(id) over(partition by id rows between unbounded preceding and unbounded following) as 'num'
from t1
),
t3 as(
select *,dense_rank() over(partition by null order by num desc) as 'rank'
from t2
)
select id,num
from t3
where t3.rank = 1
limit 1
select ifnull((
with t1 as(
select *,dense_rank() over(partition by null order by salary desc) as 'rank'
from Employee
),
t2 as(
select distinct salary as 'SecondHighestSalary'
from t1
where t1.rank = 2
)
select SecondHighestSalary from t2
),null) as 'SecondHighestSalary'