Leetcode 1369. 获取最近第二次的活动

https://leetcode-cn.com/problems/get-the-second-most-recent-activity/

with tmp as (select username,activity,startDate,endDate,row_number() over(partition by username  order by startDate desc)rk  from UserActivity)


select a.username,b.activity,b.startDate,b.endDate
from (
select a.username
,case when a.rk>=2 then 2 
      when a.rk=1 then 1 end rk 
from(
select username,max(rk)rk from tmp group by username
)a 
)a left join tmp b on a.username=b.username and a.rk=b.rk 
where b.rk is not null
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 题目选自leetcode 上的题库 可能不一定都是最优解,答案仅供参考每道题后面都应相应的难度等级,如果没时间做的...
    顾子豪阅读 788评论 2 8
  • 933. 最近的请求次数 写一个 RecentCounter 类来计算最近的请求。 它只有一个方法:ping(in...
    TheKey_阅读 748评论 0 2
  • to-do:看一下别人写的题解 https://github.com/981377660LMT/algorithm...
    winter_sweetie阅读 867评论 1 0
  • 我们提供了一个类: public class Foo { public void one() { print("o...
    山崎cc阅读 539评论 0 0
  • 序 本文主要记录一下leetcode队列之最近的请求次数 题目 题解 小结 这里使用java内置的queue,在p...
    go4it阅读 339评论 0 0

友情链接更多精彩内容