每个月的会查,想查特定的月份,比如 234 456 这样的
1
wps353 2019-08-21 18:15:26 +08:00
date_format 应该能帮助你。
|
2
yunshui OP @wps353 SELECT * FROM tbl_order GROUP BY DATE_FORMAT(CreateTime,'%Y-%m');
SELECT sum(money), DATE_FORMAT(CreateTime,'%Y-%m') FROM tbl_order GROUP BY DATE_FORMAT(CreateTime,'%Y-%m'); 这样吗? |
3
tgich 2019-08-21 18:22:11 +08:00
select * from table where year(create_time)=2019 and month(create_time) in (2,3,4);
|
5
hhhzccc 2019-08-21 19:06:22 +08:00
SELECT
sum( CASE MONTH ( a.CreateTime ) WHEN '2' THEN 1 ELSE 0 END ) AS `2`, sum( CASE MONTH ( a.CreateTime ) WHEN '3' THEN 1 ELSE 0 END ) AS `3`, sum( CASE MONTH ( a.CreateTime ) WHEN '4' THEN 1 ELSE 0 END ) AS `4` FROM tbl_order a WHERE a.CreateTime >= '2019-01-01' and a.CreateTime <= '2019-12-31'; 我觉得 where 条件后面尽量少使用函数,会破坏索引,但是如果数据量少,也无所谓了。 |
6
mmdsun 2019-08-21 19:17:11 +08:00 via Android
like 也行。
create-time like "2019-08-%" //8 月数据。 |
7
Leigg 2019-08-22 08:41:40 +08:00 via Android
where 条件语句中使用函数将导致索引失效
|
8
Leigg 2019-08-22 08:44:52 +08:00 via Android
where 00:00:00<=t<=23:59:59
|