gpt4 book ai didi

mysql - 我无法在存储过程mysql中进行算术运算

转载 作者:行者123 更新时间:2023-11-29 18:25:57 25 4
gpt4 key购买 nike

有一个 in 参数作为页面。我想做的就是从其中驱逐 1 并乘以 10。但它每次都会给我一个错误。

IF !a THEN

SELECT *
from entry
WHERE topic_foreign_id = (
select topic_id
from topic
where topic_name = topicName
)
ORDER BY entry_time ASC
LIMIT 10 OFFSET page;

ELSE

SELECT *
from entry
WHERE topic_foreign_id = (
select topic_id
from topic
where topic_name = topicName
)
ORDER BY entry_time ASC;

END IF

这行代码工作得很好,但是当我想在第一个 SQL 查询中进行算术运算时,myAdmin 每次都会抛出错误。

SELECT * 
from entry
WHERE topic_foreign_id = (
select topic_id
from topic
where topic_name = topicName
)
ORDER BY entry_time ASC
LIMIT 10 OFFSET 10 * ( page - 1); //throws error

最佳答案

--- 已编辑 ---

LIMIT 似乎不喜欢计算。尝试使用变量并在存储过程中使用该值

DECLARE v_page_offset INT DEFAULT 0;
SET v_page_offset = 10*(page-1);

然后稍后

LIMIT 10 OFFSET v_page_offset;

关于mysql - 我无法在存储过程mysql中进行算术运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46198951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com