Recently wrote a user interface to the relevant statistics, statistics are grouped according to the need to use every day.
Look directly statement
SELECT DATE_FORMAT( create_time, "%Y-%m-%d" ) ,sum(user_id) FROM orders WHERE order_state=2 GROUP BY DATE_FORMAT( create_time, "%Y-%m-%d" ) ;
复制代码
DATE_FORMAT Function Description
- grammar
DATE_FORMAT(date,format)
//上面代码中使用的是
DATE_FORMAT( create_time, "%Y-%m-%d" )
复制代码
The date argument is legitimate date. format output format predetermined date / time.
- Format format that can be used
format | description |
---|---|
%a | Abbreviated weekday name |
%b | Abbreviated month name |
%c | Month, the value |
%D | Mid-day with the English prefix |
%d | Day of the month, the value (00-31) |
%e | Day of the month, the value (0-31) |
%f | Microsecond |
%H | Hour (00-23) |
%h | Hour (01-12) |
%I | Hour (01-12) |
%i | Min, value (00-59) |
%j | On the day (001-366) |
%k | Hour (0-23) |
%l | Hour (1-12) |
%M | Month name |
%m | Month, numeric (00-12) |
%p | AM or PM |
%r | Time, 12 hours (hh: mm: ss AM or PM) |
%S | Sec (00-59) |
%s | Sec (00-59) |
%T | Time, 24 hours (hh: mm: ss) |
% U | Week (00-53) Sunday is the first day of the week |
in% | Week (00-53) Monday is the first day of the week |
% V | Week (01-53) Sunday is the first day of the week, and use% X |
% v | Week (01-53) Monday is the first day of the week, with the use of% x |
%W | Weekday name |
%w | Day of the week (0 = Sunday, 6 = Saturday) |
%X | In, where Sunday is the first day of the week, four, and use% V |
%x | In which the first day of the week is Monday, 4, use% v |
%Y | Year 4 |
%Y | Year 2 |
Welcome to my public concern number - programmers growth refers to the North. Your own micro-letter search - "Programmer growth refers to the North."
Previous article: How to Write an elegant native SQL statements?