【发布时间】:2019-09-22 22:37:00
【问题描述】:
我会简短:
工作中
SELECT p.id,
p.name,
cat.name `category`,
prod.name `producer`,
p.images,
p.price,
p.flag_avaliable,
p.amount,
p.description,
p.options
FROM product p
INNER JOIN product_category cat ON cat.id = p.category_id
INNER JOIN product_producer prod ON prod.id = p.producer_id
ORDER BY @asc_or_desc
limit 5 offset 6;
不工作
set @asc_or_desc = 'id desc ';
set @limit_number = 5;
set @offset_number = 6;
SELECT p.id,
p.name,
cat.name `category`,
prod.name `producer`,
p.images,
p.price,
p.flag_avaliable,
p.amount,
p.description,
p.options
FROM product p
INNER JOIN product_category cat ON cat.id = p.category_id
INNER JOIN product_producer prod ON prod.id = p.producer_id
ORDER BY @asc_or_desc
limit @limit_number offset @offset_number;
所以,我需要“不工作”版本才能工作。我怎样才能做到这一点?
我有同样的错误:'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 '@limit_number offset @offset_number; END''。
为什么?类型没问题,你看... 什么问题?也许值可以用一些错误代替?
我正在使用 JetBrains DataGrip,MySQL 8.0.15。
【问题讨论】:
-
如果有的话,使用动态SQL或者用客户端的语言构建查询。
-
@stickybit,你的意思是准备好的陈述?
-
是的,这是可能的。
-
@stickybit,好的,那行得通。我以为,sql 有更多的可能
标签: mysql sql select stored-procedures user-variables