如何从mysql表中获取前一天的记录? [英] How to get the previous day records from mysql table?

查看:269
本文介绍了如何从mysql表中获取前一天的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从表中获取前一天的记录,但是我没有找到确切的方法.请需要您的帮助..

I am trying to fetch previous day records from table but I am not finding how to do it exactly. Need your help please..

表:RECORD_DATA

Table: RECORD_DATA

id       creationDate    
1   | 2013-05-03 04:03:35 |    
2   | 2013-05-03 04:03:35 | 

现在,我需要获取在2013-05-03创建的所有记录.时间可以是任何事情.因此,我的查询应具有LIKE运算符.

Now I need to get all the records that were created on 2013-05-03. Time can be anything. So my query should have LIKE operator.

我正在使用下面的查询,它给了我一个空集.

I am using below query and it gives me empty set.

select creationDate from RECORD_DATA 
where creationDate LIKE DATE_SUB(STR_TO_DATE('2012-04-05','%d/%m/%Y'),INTERVAL 1 DAY);

推荐答案

使用SQL完成后非常简单,只需添加条件

Fairly simple when done with SQL, just add the condition

WHERE creationDate BETWEEN CURDATE() - INTERVAL 1 DAY AND CURDATE()

无需转换creationDate,因为它已经是一个日期:).而且我相信这将是最快的检查方法(如果您查看大量数据集,这将很重要).

There is no need to convert creationDate as it is already a date :). And i belive that this will be the fastest way to check it (which will matter if you go over large data sets).

这篇关于如何从mysql表中获取前一天的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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