SQL to determine minimum sequential days of access?

前端 未结 19 1691
我在风中等你
我在风中等你 2020-12-04 04:58

The following User History table contains one record for every day a given user has accessed a website (in a 24 hour UTC period). It has many thousands of r

19条回答
  •  [愿得一人]
    2020-12-04 05:13

    Something like this?

    select distinct userid
    from table t1, table t2
    where t1.UserId = t2.UserId 
      AND trunc(t1.CreationDate) = trunc(t2.CreationDate) + n
      AND (
        select count(*)
        from table t3
        where t1.UserId  = t3.UserId
          and CreationDate between trunc(t1.CreationDate) and trunc(t1.CreationDate)+n
       ) = n
    

提交回复
热议问题