<!-- 按日查询 --> SELECT DATE_FORMAT(created_date,'%Y-%m-%d') as time,sum(money) money FROM o_finance_detail where org_id = 1000 GROUP BY time <!-- 按月查询 --> SELECT DATE_FORMAT(created_date,'%Y-%m') as time,sum(money) money FROM o_finance_detail where org_id = 1000 GROUP BY time <!-- 按年查询 --> SELECT DATE_FORMAT(created_date,'%Y') as time,sum(money) money FROM o_finance_detail where org_id = 1000 GROUP BY time <!-- 按周查询 --> SELECT DATE_FORMAT(created_date,'%Y-%u') as time,sum(money) money FROM o_finance_detail where org_id = 1000 GROUP BY time
DATE_FORMAT(date,format) Format 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 day of the month with an English prefix (1st, 2nd, 3rd, etc.) % Y year, number, 4 digits % y year, number, 2 digits % a Abbreviated week name (Sun...Sat) % d day of month, number ( 00 ... 31 ) % e day of month, number ( 0 ... 31 ) % m month, number( 01 ...... 12 ) % c month, number ( 1 ...... 12 ) % b abbreviated month name (Jan ...... Dec ) % j day of the year (001 ... 366 ) % H hours ( 00 ... 23 ) % k hours ( 0 ... 23 ) % h hours ( 01 ... 12 ) % I hours ( 01 ... 12 ) % l hours ( 1 ... 12 ) % i minutes, numbers ( 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 of the week ( 0 = Sunday... 6 = Saturday) % U week( 0 ... 52 ), here Sunday is the first day of the week % u week ( 0 ... 52 ), where Monday is the first day of the week %% a literal " % ".
Group by time to count the rowspan span of the table
$cjrili_group = Db::query("SELECT time,count(*) row_num FROM think_cjrili where 1 GROUP BY time");