MySQL查询从上周选择数据? [英] MySQL Query to select data from last week?

查看:181
本文介绍了MySQL查询从上周选择数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个表有日期字段和一些其他信息。
我想选择上周的所有条目(从星期日开始的周)。

Hi I have a table with a date field and some other informations. I want to select all entries from the last 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 15是当前周。)

I want to select all ids from last week, expected out out is 5, 6, 8. (id 2 not in last week, and id 15 is in current week.)

如何编写和SQL查询相同。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆