设timestamp为datetime类型 则 按月统计 select MONTH(timestamp), count(*) from data group by 1 按周统计 select WEEK(timestamp), count(*) from data group by 1 按月和天统计 select MONTH(timestamp), DAYOFMONTH(timestamp), count(*) from data group by 1,2 按一年中的天数统计 select DAYOFYEAR(timestamp), count(*) from data group by 1 ....
或者mysql有没有这样的日期函数来实行类选?
则
按月统计
select MONTH(timestamp), count(*) from data group by 1
按周统计
select WEEK(timestamp), count(*) from data group by 1
按月和天统计
select MONTH(timestamp), DAYOFMONTH(timestamp), count(*) from data group by 1,2
按一年中的天数统计
select DAYOFYEAR(timestamp), count(*) from data group by 1
....
1、我的timestamp如果是用unix时间戳保存的,得另外建一个字段用来保存datetime这种类型的值吧?如果timestamp直接使用datetime类型,它可以选择大于某天的所有日期么?用来统计本月本日访问总量用的。
2、唠叨为什么要group by?
如果我全部改成datetime的,该类型是否支持大小对比?
我可以在mysql中得到某个时间,比如1992-05-02 02:03:02这个时间的当天起始时间么?