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