table_name 为表名
time 为日期字段
1、按月分组:
select month(FROM_UNIXTIME(time))
from table_name
group by month(FROM_UNIXTIME(time))
2、按年月分组:
select DATE_FORMAT(FROM_UNIXTIME(time),"%Y-%m")
from table_name
group by DATE_FORMAT(FROM_UNIXTIME(time),"%Y-%m")
或者:
select FROM_UNIXTIME(time,"%Y-%m")
from table_name
group by FROM_UNIXTIME(time,"%Y-%m")
3、按年月日分组:
select DATE_FORMAT(FROM_UNIXTIME(time),"%Y-%m-%d")
from table_name
group by DATE_FORMAT(FROM_UNIXTIME(time),"%Y-%m-%d")
或者:
select FROM_UNIXTIME(time,"%Y-%m-%d")
from table_name
group by FROM_UNIXTIME(time,"%Y-%m-%d")
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。