连续N天登陆

160 阅读1分钟
select stock_id,count(*) ,startdate
from 
(select *,(dated - (rown * interval '1 day')) as startdate 
    from
         (select *,row_number() over(PARTITION by stock_id order by dated) as rown
             from 
                (select distinct stock_id, date as dated 
                      from stockbars ) a
          ) b
)c 
GROUP BY stock_id,startdate
 having count(*)>=3;