对比牛客的课程订单分析(四),这道题多了一个second_buy_date字段,想到用偏移函数,parition by user_id用户分组,order by date,对日期升序排序,默认偏移一个单位刚好是第二次购买。 SELECT user_id ,min( date ) AS first_buy_date ,second_buy_date ,cnt FROM ( SELECT *, count( * ) over ( PARTITION BY user_id ) AS cnt, lead(d...