MySQL by day, by week, by month, by quarter, by year statistics

Source: Internet
Author: User

SELECTCount(ID) fromRd_track_infoWHEREDATE (create_time)<Date_sub (Curdate (), INTERVAL7  Day);SELECTCount(ID) fromRd_track_infoWHEREDATE (create_time)=Date_sub (Curdate (), INTERVAL7  Day);SELECTCount(ID) fromRd_track_infoWHEREDATE (create_time)>Date_sub (Curdate (), INTERVAL7  Day);

/* statistics by day */
SELECT    Count(ID) countnum, DATE (create_time) createtime fromRd_track_infoGROUP  byDATE (create_time)ORDER  byDATE (create_time)DESC;/*statistics by week*/SELECT    Count(ID) countnum, WEEK (create_time) createtime fromRd_track_infoGROUP  byWEEK (create_time)ORDER  byWEEK (create_time)DESC;/*Monthly Statistics*/SELECT    Count(ID) countnum,MONTH(create_time) createtime fromRd_track_infoGROUP  by    MONTH(create_time)ORDER  by    MONTH(Create_time)DESC;/*Statistics by Quarter*/SELECT    Count(ID) countnum, QUARTER (create_time) createtime fromRd_track_infoGROUP  byQUARTER (create_time)ORDER  byQUARTER (create_time)DESC;/*by year statistics*/SELECT    Count(ID) countnum, Year(create_time) createtime fromRd_track_infoGROUP  by     Year(create_time)ORDER  by     Year(Create_time)DESC;

MySQL by day, by week, by month, by quarter, by year statistics

Related Article

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.