How to track that a user visited the site each day for X days?

后端 未结 5 946
情深已故
情深已故 2021-02-04 16:41

There is a new badge on Stack Overflow. The \"woot\" badge is awarded to users visited the site each day for 30 days. How can you implement a feature like this? How can you trac

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 17:34

    Actually, if the Member's visits are in a SQL database, you can do the whole thing with a single SQL query. This is also probably faster than schlepping all of the data over to a client program to check it anyway:

    /*
        Find all members who visited at least once every day
      for 30 or more days.  --RBarryYoung, 2009-05-31
    */
    ;WITH
      cteVisitDays as (
        Select
          MemberID
        , DATEDIFF(dd,'2008-06-01',VisitTime) as VisitDay
         From tblMembersLog
         Where Not Exists( Select * From tblMemberTags T
        Where T.MemberID = tblMembersLog.MemberID
         And T.TagName = 'WOOT!' )
         Group By MemberID
            , DATEDIFF(dd,'2008-06-01',VisitTime)
        )
    , cteVisitRunGroups as (
        Select 
          MemberID
        , VisitDay - Row_Number() Over(
                Partition By MemberID
                Order By VisitDay
            ) as RunGrouping
         From cteVisitDays
         )
    SELECT Distinct
      MemberID
     From cteVistRunGroups
     Group By MemberId, RunGrouping
     Having COUNT(*) >= 30
    

提交回复
热议问题