MySQL group statistics by week, month, day

Source: Internet
Author: User
Tags month name

<!--query by day --SELECTDate_format (Created_date,'%y-%m-%d') asTimesum( Money) Money  fromO_finance_detailwhereorg_id=  +  GROUP  by Time<!--Monthly Query --SELECTDate_format (Created_date,'%y-%m') asTimesum( Money) Money  fromO_finance_detailwhereorg_id=  +  GROUP  by Time<!--Search by year --SELECTDate_format (Created_date,'%Y') asTimesum( Money) Money  fromO_finance_detailwhereorg_id=  +  GROUP  by Time<!--Weekly Query --SELECTDate_format (Created_date,'%y-%u') asTimesum( Money) Money  fromO_finance_detailwhereorg_id=  +  GROUP  byTime

Date_format (Date,format) formats the DATE value according to the format string. The following modifiers can be used in the format string:%M-month name (January ... December)%W-week name (Sunday ... Saturday)%D The date of the month with English prefixes (1st, 2nd, 3rd, etc.). )%Y years, numbers,4bit%Y years, numbers,2bit%a abbreviated weekday name (Sun ... Sat)%Number of days in the D-month, number (xx...... to) %Number of days in the E-month, number (0...... to) %M-month, number ( on...... A) %C Month, number (1...... A) %b Abbreviated month name (Jan ...Dec) %J Number of Days in a year (001......366) %H Hours (xx...... at) %K Hours (0...... at) %H Hours ( on...... A) %I-Hour ( on...... A) %L Hours (1...... A) %I minute, number (xx...... -) %R time, AHours (hh:mm:ss[AP]M)%T time, -hours (HH:MM:SS)%s seconds (xx...... -) %s seconds (xx...... -) %P AM or PM%W one days in the week (0=Sunday ...6=Saturday)%U Week (0...... the), here Sunday is the first day of the week%U Week (0...... the), here Monday is the first day of the week%%A text "%”。

RowSpan span of table by TIME group

$cjrili _group = Db::query ("Select Time,count (*)  row_num from Think_cjrili where 1  group by Time  ") ;

MySQL group statistics by week, month, day

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.