1. 程式人生 > >獲取資料庫當天,前一天的資料

獲取資料庫當天,前一天的資料

獲取資料庫中當天的資料

SELECT user_id,timestamp

FROM hoomic.t_mobile_sesion

where date_format(timestamp,'%Y%m%d') = date_format(now(), '%Y%m%d')

order by timestamp desc;

獲取資料庫中前一天的資料

方法一

SELECT * FROM hoomic.t_mobile_sesion where date_format(timestamp,'%Y%m%d') = date_format(adddate(now(),-1),'%Y%m%d') order by timestamp desc;

方法二

SELECT * FROM hoomic.t_mobile_sesion where date_format(timestamp,'%Y%m%d') = date_format(DATE_ADD(now(),INTERVAL -1 DAY),'%Y%m%d') order by timestamp desc;