比如数据库中存的时间类型是DAYETIME类型,在数据库中会记录 年月日时分秒,2013-01-14 23:33:47
当想用时间中的小时来分组,可以使用如下语句:
select * from table group by date_format(time,'%k');
这样查出来的结果就是按时间中的小时来分组的。%k是24小时制,%h是12小时制
如果需要把日期也加进去,就用如下形式:
selectdate_format(time,'%Y-%m-%d'),date_format(time,'%k') from t_web_user_access group by date_format(time,'%Y-%m-%d %k');
这就是按照一天中的小时进行分组