例子1:
比如说有4条数据是
2014—8— 24
2014—8— 08
2014—9— 24
2014—9— 08
SELECT distinct date_format(create_time,'%Y-%m') from table1;
结果:
2014—8
2014—9
例子2
时间字段数据
时间格式转换
select date_format(gmt_create,'%Y-%m-%d') time from table1 where gmt_create between '2021-01-12 00:00:00' and '2021-01-26 00:00:00';
根据月份去重
select distinct date_format(gmt_create,'%Y-%m') from table1 where gmt_create between '2021-01-12 00:00:00' and '2021-01-26 00:00:00';
根据月份去重后再计数
select COUNT( distinct date_format(gmt_create,'%Y-%m-%d') ) from table1 where gmt_create between '2021-01-12 00:00:00' and '2021-01-26 00:00:00';