select distinct from_user, realname, mobile from `testtable`
where id = “2” and storeid =”5″ LIMIT (1-1)*10,10
报错信息为:
—
错误
—
SQL 执行错误 # 1064. 从数据库的响应:
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 “(1-1)*10,10” at line 2
—
确定
—
请教,这个是什么原因?
where id = “2” and storeid =”5″ LIMIT (1-1)*10,10
报错信息为:
—
错误
—
SQL 执行错误 # 1064. 从数据库的响应:
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 “(1-1)*10,10” at line 2
—
确定
—
请教,这个是什么原因?
解决方案
10
limit 后面是不能做计算的,只能直接写 limit xx
5
在外部程序计算好,然后再传给MySQL吧
5
用动态SQL应该可以办到,大致是这样
set @ms=concat (“select distinct from_user, realname, mobile from testtable where id = ? and storeid = ? LIMIT “, (1-1)*10, “,10”;
set @p1 = “2”;
set @p2 = “5”;
PREPARE s1 from @ms;
EXECUTE s1 USING @p1, @p2;
deallocate prepare s1;
set @ms=concat (“select distinct from_user, realname, mobile from testtable where id = ? and storeid = ? LIMIT “, (1-1)*10, “,10”;
set @p1 = “2”;
set @p2 = “5”;
PREPARE s1 from @ms;
EXECUTE s1 USING @p1, @p2;
deallocate prepare s1;