按小时显示

select timestamp,count(*) as test from browserinfo group by date_format(timestamp, '%Y-%m-%d %H ');

查询今天,昨天,近7天,近30天,本月,上一月

select * from `browserinfo` where date_format(`timestamp`,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d');                //当天
select * from `browserinfo` where to_days(date_format(`timestamp`,'%Y-%m-%d')) = to_days(now());                      //当天,效果同上一条
select * from `browserinfo` where to_days(`timestamp`) = to_days(now());                                              //当天,效果同上两条
select * from `browserinfo` where to_days(now())-to_days(`timestamp`) <= 1;                                           //昨天
select * from `browserinfo` where date_sub(curdate(), INTERVAL 7 DAY) <= date(`timestamp`);                           //最近七天
select * from `browserinfo` where date_sub(curdate(), INTERVAL 30 DAY) <= date(`timestamp`);                          //最近三十天
select * from `browserinfo` where date_format(`timestamp`, '%Y%m') = date_format(curdate() , '%Y%m');                 //本月
select * from `browserinfo` where period_diff(date_format(now() , '%Y%m') , date_format(`timestamp`, '%Y%m')) =1;     //上个月
作者 铁血 汉子 2017年8月8日
2017/12/11/01:16:15pm 2017/8/8/17:24:49
0 175