我想运行MYSQL查询来获取前一周的数据。 date列的数据类型是DATETIME。谁有人建议?
答案 0 :(得分:10)
SELECT *
FROM calendar
WHERE dt BETWEEN CURDATE()-INTERVAL 1 WEEK AND CURDATE();
答案 1 :(得分:1)
这是另一个版本:
SELECT * FROM table WHERE
YEARWEEK(`date`, 1) = YEARWEEK( CURDATE() - INTERVAL 1 WEEK, 1)
答案 2 :(得分:0)
SELECT id FROM tbl
WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
答案 3 :(得分:-1)
为当前日期时间 - 1周制作变量并进行此查询:
SELECT * FROM table WHERE date > $datatime