MySQL statistics function record-monthly, quarterly, by day, time period

Source: Internet
Author: User

Aggregated by year, statistics:
Select SUM (Mymoney) as Totalmoney, COUNT (*) as sheets from MyTable Group by Date_format (Col, '%Y ');
Summary by month, statistics:
Select SUM (Mymoney) as Totalmoney, COUNT (*) as sheets from MyTable Group by Date_format (Col, '%y-%m ');
Summary by quarter, statistics:
Select SUM (Mymoney) as Totalmoney,count (*) as sheets from MyTable Group by concat (Date_format (col, '%Y '), Floor (date_form At (Col, '%m ') +2)/3);
Select SUM (Mymoney) as Totalmoney,count (*) as sheets from MyTable Group by concat (Date_format (col, '%Y '), Floor (date_form At (Col, '%m ') +2)/3);
By hour:
Select SUM (Mymoney) as Totalmoney,count (*) as sheets from MyTable Group by Date_format (Col, '%y-%m-%d%H ');
Query this year's data:
SELECT * FROM MyTable WHERE year (From_unixtime (my_time)) = year (Curdate ())
Number of quarters with query data included:
SELECT ID, Quarter (from_unixtime (my_time)) from MyTable;
Query the data for this quarter:
SELECT * FROM MyTable WHERE quarter (From_unixtime (my_time)) = Quarter (Curdate ());
Monthly statistics:
SELECT * FROM MyTable where month (my_time1) = month (Curdate ()) and year (my_time2) = year (Curdate ())
This week's stats:
SELECT * FROM MyTable where month (my_time1) = month (Curdate ()) and week (my_time2) = Week (Curdate ())

MySQL statistics function record-monthly, quarterly, by day, time period

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.