SQL to determine minimum sequential days of access?

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

    Doing this with a single SQL query seems overly complicated to me. Let me break this answer down in two parts.

    1. What you should have done until now and should start doing now:
      Run a daily cron job that checks for every user wether he has logged in today and then increments a counter if he has or sets it to 0 if he hasn't.
    2. What you should do now:
      - Export this table to a server that doesn't run your website and won't be needed for a while. ;)
      - Sort it by user, then date.
      - go through it sequentially, keep a counter...

提交回复
热议问题