MySQL查询从上周选择数据? [英] MySQL Query to select data from last week?
本文介绍了MySQL查询从上周选择数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择上周的所有条目(从星期日开始的星期)。
表值:
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
我想从上周选择所有ids,预期输出是5,6,8。
(id 2 not在上周,ID 15在本周。)
如何写和SQL查询相同。
解决方案
SELECT id FROM tbl
WHERE date> = curdate() - INTERVAL DAYOFWEEK(curdate() +6 DAY
AND date< curdate() - INTERVAL DAYOFWEEK(curdate()) - 1 DAY
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).
table values:
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
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.)
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查询从上周选择数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文