How to count and query continuous check-ins and cumulative check-ins in mysql

WBOY
Release: 2016-08-25 10:37:19
Original
3114 people have browsed it

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

Reply content:

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>
Copy after login

Second:
mysql does not support hierarchical query, and sql is not easy to handle

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!