文章目录
-
- 原题题目
- 代码实现(首刷学习 Lead函数)
原题题目
代码实现(首刷学习 Lead函数)
# Write your MySQL query statement below
SELECT user_id,MAX(DATEDIFF(IF(next_date is null,"2021-1-1",next_date),visit_date)) biggest_window
FROM (SELECT user_id,visit_date,LEAD(visit_date,1) OVER(PARTITION BY user_id ORDER BY visit_date) AS next_dateFROM uservisits) t1
GROUP BY user_id