SQL LIMIT语法错误 [英] SQL LIMIT syntax error

查看:802
本文介绍了SQL LIMIT语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是全部:

SELECT * FROM sometable LIMIT 5*DATEDIFF(NOW(), '2011-08-30'), 5

错误:

您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本以使用正确的语法 第1行的'* DATEDIFF(NOW(),'2011-08-30'),5'附近

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*DATEDIFF(NOW(), '2011-08-30'), 5' at line 1

问题显然是LIMIT显然不接受任何东西,但接受整数.它也不会接受1+1(1+1)作为值.有办法解决吗?

The problem is clearly that LIMIT does not accept anything but integer apparently. It won't accept 1+1 or (1+1) as value either. Is there a way around it?

这样您就不必去尝试了,5*DATEDIFF(NOW(), '2011-08-30')正常就可以了.

And just so you don't have to go and try, 5*DATEDIFF(NOW(), '2011-08-30') works just fine.

我正在尝试修复推荐答案

,在普通mysql中不可用
(但是,可以通过存储过程,用户定义的函数来实现)

NO, is not doable in plain mysql
(however, is possible via stored procedure, user defined function)

您的情况下,可以通过PHP调用轻松替换

your case, it can easily replaced via a PHP call

$offset = 5*
        date_diff(new DateTime('now'), new DateTime('2011-08-31'))->format('%a');
$sql = "SELECT * FROM sometable LIMIT {$offset},5";

这篇关于SQL LIMIT语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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