本文先列出一些常用到的mysql查询语句,方便以后查阅。

查询当天的数据

SELECT * FROM `table` WHERE date_format(from_UNIXTIME(`addtime`),'%Y-%m-%d') = date_format(DATE_SUB(curdate(), INTERVAL 1 DAY),'%Y-%m-%d');

查询昨天的数据

SELECT * FROM `table` WHERE date_format(from_UNIXTIME(`addtime`),'%Y-%m-%d') = date_format(NOW(),'%Y-%m-%d');

查询本周的数据

SELECT * FROM `table` WHERE YEARWEEK(date_format(addtime,'%Y-%m-%d')) = YEARWEEK(NOW());

查询上周的数据

SELECT * FROM `table` WHERE YEARWEEK(date_format(addtime,'%Y-%m-%d')) = YEARWEEK(NOW())-1;

查询本月的数据

SELECT * FROM `table` WHERE date_format(addtime,'%Y-%m') = date_format(NOW(),'%Y-%m');

查询本年数据

SELECT * FROM `table` WHERE YEAR(addtime) = YEAR(NOW());

via。http://www.hehaibao.com/mysql-querys/

最后修改:2017 年 08 月 12 日 12 : 53 AM