How MySQL counts consecutive check-ins and cumulative sign-ins

Source: Internet
Author: User
Two questions: First, query the number of times accumulated check-in within a specified time (similar to post-bar, each user can go to each organization to check in once, but regardless of the user in several organizations sign in, as long as the registration of an organization, even if this day check-in, the statistics within the specified time interval accumulated registration for several days). Second, count the maximum number of consecutive sign-in days for the specified time period

Reply content:

Two questions: First, query the number of times accumulated check-in within a specified time (similar to post-bar, each user can go to each organization to check in once, but regardless of the user in several organizations sign in, as long as the registration of an organization, even if this day check-in, the statistics within the specified time interval accumulated registration for several days). Second, count the maximum number of consecutive sign-in days for the specified time period

The first one turns the time around (for example, with the To_days function) and then wakes up with a distinct.
The second is to use SQL to feel a bit of trouble, rather than in the application to calculate

The first one:

select 用户, count(distinct 签到日期)from tablewhere 签到日期 between 起始日期 and 结束日期group by 用户

The second one:
MySQL does not support hierarchical query, SQL bad processing

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.