mysql怎么查询今天的数据
导读
建表:
CREATE TABLE ` order ` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `order_name` VARCHAR (45) NOT NULL , `order_time` DATETIME NOT NULL , PRIMARY KEY (`id`) )
查询当天(今天)的数据
SELECT * FROM ` order ` WHERE TO_DAYS(order_time) = TO_DAYS(NOW())
查询昨天的数据
SELECT * FROM ` order ` WHERE TO_DAYS(NOW()) - TO_DAYS(order_time) = 1
查询当月(本月)的数据
SELECT * FROM `order` WHERE DATE_FORMAT(order_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')
评论(0)