mySQL从过去24小时,最后60分钟尝试发帖 [英] mySQL failed attempt at getting posts from last 24hr, and last 60 min

查看:216
本文介绍了mySQL从过去24小时,最后60分钟尝试发帖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定编辑这个...

SELECT *
FROM votelog
WHERE ipaddress = '127.0.0.1'
AND datevoted
BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 24 HOUR )
AND CURDATE( )
LIMIT 0 , 30

这是我试图运行在过去24小时内查找帖子的示例。我也是在过去60分钟内为不同的需要运行一个单独的。问题是表中至少有4行在测试,其中3行属于24小时条款。

That is an example of the query I am attempting to run to find posts within the past 24 hours. I am also running a separate one for different needs for in the past 60 minutes. Issue is there is at least 4 rows in the table I am testing with 3 of which fall under the 24 hour clause.

好吧,所以我想出了我的问题,1我很累.. 2可怕的使用Between和Date_Sub ..它没有黎明在我,直到现在我应该使用col名称,我有CURDATE()将在下面回答我自己的问题。

Ok so I figured out my problem, 1 Im to damn tired.. 2 Horrible use of Between and Date_Sub.. It didn't dawn on me till now I should have been using the col name where I have CURDATE() going to answer my own question below.

这是DB中时间戳的样子,标准DATETIME .. 2011-09-01 13:20: 08

this is what the timestamp in the DB looks like, standard DATETIME.. 2011-09-01 13:20:08

据说我没有得到结果。

with that being said I am yielding no results.

推荐答案

您没有正确使用BETWEEN,正确的语法是:

You are not using BETWEEN correctly, the correct syntax is:

expr BETWEEN min AND max

expr BETWEEN min AND max

您应该将查询的结尾更改为:

you should change the end of your query to:

...BETWEEN DATE_SUB(CURDATE(), INTERVAL 24 hour) AND CURDATE()

或使用> 运算符。

这篇关于mySQL从过去24小时,最后60分钟尝试发帖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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