Two questions: First, query the cumulative number of sign-ins within a specified period (similar to Tieba, each user can sign in once to each organization, but no matter how many organizations the user signs in to, as long as they sign in to one organization, they will be counted as signed in on that day) , counting the number of accumulated check-ins within the specified time interval). Second, count the longest number of consecutive check-in days within a specified period of time
Two questions: First, query the cumulative number of sign-ins within a specified period (similar to Tieba, each user can sign in once to each organization, but no matter how many organizations the user signs in to, as long as they sign in to one organization, they will be counted as signed in on that day) , counting the number of accumulated check-ins within the specified time interval). Second, count the longest number of consecutive check-in days within a specified period of time
The first one converts the time into days (for example, using the TO_DAYS function), and then DISTINCT wakes up
The second one is a bit troublesome to use sql, it is better to calculate it in the application
First one:
<code>select 用户, count(distinct 签到日期) from table where 签到日期 between 起始日期 and 结束日期 group by 用户 </code>
Second:
mysql does not support hierarchical query, and sql is not easy to handle