Count number of consecutive visits

后端 未结 2 1253
一生所求
一生所求 2021-01-07 10:14

Every time a logged in user visits the website their data is put into a table containing the userId and date (either one or zero row per user per day):

   44         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-07 10:57

    If it is not necessary to have a log of every day the user was logged on to the webiste and you only want to know the consecutive days he was logged on, I would prefer this way:

    Chose 3 columns: LastVisit (Date), ConsecutiveDays (int) and User.

    On log-in you check the entry for the user, determine if last visit was "Today - 1", then add 1 to the columns ConsecutiveDays and store "Today" in column LastVisit. If last vist is greater than "Today - 1" then store 1 in ConsecutiveDays.

    HTH

提交回复
热议问题