MySql grouping statistics by week, month, or day

Source: Internet
Author: User
Tags month name


Knowledge keywords: DATE_FORMAT select DATE_FORMAT (create_time, '% Y % U') weeks, count (caseid) count from tc_case group by weeks; select DATE_FORMAT (create_time, '% Y % m % D') days, count (caseid) count from tc_case group by days; select DATE_FORMAT (create_time,' % Y % m') months, count (caseid) count from tc_case group by months; DATE_FORMAT (date, format)
Format the date value based on the format string. The following modifier can be used in the format string: % M month name (January ...... December) % W name of the Week (Sunday ...... Saturday) % D Date of the month with an English prefix (1st, 2nd, 3rd, and so on .) % Y year, number, 4-digit www.2cto.com % y year, number, 2-digit % a abbreviation of the week name (Sun ...... Sat) % d number of days in the month (00 ...... 31) % e number of days in the month (0 ...... 31) % m month, number (01 ...... 12) % c month, number (1 ...... 12) % B abbreviated month name (Jan ...... Dec) % j days in a year (001 ...... 366) % H hour (00 ...... 23) % k hour (0 ...... 23) % h hour (01 ...... 12) % I hour (01 ...... 12) % l hour (1 ...... 12) % I minute, number (00 ...... 59) % r time, 12 hours (hh: mm: ss [AP] M) % T time, 24 hours (hh: mm: ss) % S seconds (00 ...... 59) % s seconds (00 ...... 59) % p AM or PM % w days in a week (0 = Sunday ...... 6 = Saturday) % U Week (0 ...... 52), here Sunday is the first day of the week % u Week (0 ...... 52), Monday is the first day of the week % A text "% ".
Author: jieke_ZJ

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.