SQL to determine minimum sequential days of access?

前端 未结 19 1694
我在风中等你
我在风中等你 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:33

    Spencer almost did it, but this should be the working code:

    SELECT DISTINCT UserId
    FROM History h1
    WHERE (
        SELECT COUNT(*) 
        FROM History
        WHERE UserId = h1.UserId AND CreationDate BETWEEN h1.CreationDate AND DATEADD(d, @n-1, h1.CreationDate)
    ) >= @n
    
    0 讨论(0)
提交回复
热议问题