I have the following prepare statement in which I have kept the limit clause variable -
我有以下准备语句,其中我保留了limit子句变量 -
PREPARE fooStmt FROM "SELECT id FROM Table_1 ORDER BY id LIMIT ?";
I define a variable @record -
我定义了一个变量@record -
SET @record = 4;
Now I use the above variable to execute the prepared statement -
现在我使用上面的变量来执行预准备语句 -
EXECUTE fooStmt USING @record;
I get the below result -
我得到以下结果 -
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
+----+
Now my problem is that I want the max id from the above result. I tried the below query for obtaining the desired result, but it gives me SQL syntax error :
现在我的问题是我想要上面结果的最大ID。我尝试了以下查询来获得所需的结果,但它给了我SQL语法错误:
select max(id) from (EXECUTE fooStmt USING @record);
ERROR 1064 (42000): 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 'USING @record)' at line 1
Can you please help me to identify the problem and how can I get my desired result?
你能帮我解决一下这个问题吗?我怎样才能得到我想要的结果?
2 个解决方案
#1
1
Try this please:
请试试这个:
PREPARE fooStmt
FROM "SELECT max(id) AS id FROM ( SELECT id FROM frameThreshold ORDER BY id LIMIT ? ) AS id";
#2
0
If you need you should (re)prepare the sql
如果你需要,你应该(重新)准备sql
"select max(id) from
(SELECT id FROM Table_1 ORDER BY id LIMIT ?) as t";
then
PREPARE your_maxFooStmt FROM "select max(id) from
(SELECT id FROM Table_1 ORDER BY id LIMIT ?) as t";
#1
1
Try this please:
请试试这个:
PREPARE fooStmt
FROM "SELECT max(id) AS id FROM ( SELECT id FROM frameThreshold ORDER BY id LIMIT ? ) AS id";
#2
0
If you need you should (re)prepare the sql
如果你需要,你应该(重新)准备sql
"select max(id) from
(SELECT id FROM Table_1 ORDER BY id LIMIT ?) as t";
then
PREPARE your_maxFooStmt FROM "select max(id) from
(SELECT id FROM Table_1 ORDER BY id LIMIT ?) as t";