我有一个带有日期字段和一些其他信息的表格.我想选择过去一周的所有条目,(一周从星期日开始).
Hi I have a table with a date field and some other information. I want to select all entries from the past week, (week start from Sunday).
表值:
id date
2 2011-05-14 09:17:25
5 2011-05-16 09:17:25
6 2011-05-17 09:17:25
8 2011-05-20 09:17:25
15 2011-05-22 09:17:25
我想选择上周的所有 id,预期输出为 5、6、8.(id 2 不在上周,id 15 在本周.)
I want to select all ids from last week, expected output is 5, 6, 8. (id 2 not in last week, and id 15 is in current week.)
如何写和SQL Query一样.
How to write and SQL Query for the same.
SELECT id FROM tbl
WHERE date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND date < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
这篇关于MySQL查询从上周选择数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!