select * from wap_content where week(created_at) = week(now) 如果你要严格要求是某一年的,那可以这样 查询一天: select * from table where to_days(column_time) = to_days(now()); select * from table where date(column_time) = curdate(); 查询一周: select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time); 查询一个月: select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(column_time); 查询选择所有 date_col 值在最后 30 天内的记录。 mysql> SELECT something FROM tbl_name WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;查询时间段:
例子:查询某市级订单数量:(订单地址表存有县区级id)
=== (最近一周SQL,直接可用)
SELECT
city.`name`,
city.id,
count(order_deliver_address.order_id)
FROM
order_deliver_address
INNER JOIN region AS area ON order_deliver_address.region_id = area.id
INNER JOIN region AS city ON area.pid = city.id
INNER JOIN region AS province ON city.pid = province.id
INNER JOIN `order` o ON o.id = order_deliver_address.order_id
where province.id = '2148'
and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(o.create_date)
GROUP BY city.id
参考网站:
(1)http://zhidao.baidu.com/link?url=dV2TqGmVt6Ip9dhAF-WRp6VAWYzeST21rgXHualLvjWNKZbAG_QIhoTfWoN7R6Z6pGoIlVsHFEPnxs9nDkeLJa
(2)http://www.jbxue.com/db/17595.html
(3)http://www.2cto.com/database/201204/126711.html