mysql超时 60分钟,mySQL从过去24小时,最后60分钟尝试发帖

博客作者在尝试查找过去24小时内的投票记录时遇到了问题,原本的SQL查询语句未能返回预期结果。经过分析,发现错误在于对BETWEEN和DATE_SUB的不正确使用。解决方案是调整查询语句,正确使用BETWEEN语法或采用>运算符,以匹配日期时间戳格式的数据库记录。
摘要由CSDN通过智能技术生成

Ok Editing this...

SELECT *

FROM votelog

WHERE ipaddress = '127.0.0.1'

AND datevoted

BETWEEN DATE_SUB( CURDATE( ) , INTERVAL 24 HOUR )

AND CURDATE( )

LIMIT 0 , 30

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.

Edit

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.

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.

解决方案

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

expr BETWEEN min AND max

you should change the end of your query to:

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

or use > operator.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值