所以我有一个看起来像这样的过程
CREATE PROCEDURE slct()
BEGIN
DECLARE ttl INT DEFAULT 0;
SELECT NULL AS price, NULL AS account_id, NULL as max_amount, NULL as total
FROM sellers
UNION ALL
SELECT price, account_id, max_amount, ttl := ttl + max_amount
FROM (SELECT * FROM sellers ORDER BY price ASC) C where selling_currency_id = :buying and buying_currency_id = :buying_with and ttl < :quantity
END它给了我一个语法错误,因为这里的海象操作符:ttl := ttl + max_amount。如果这是一个用户变量(@ttl),海象操作符就可以工作,但是@ttl没有限定作用域的事实会在我的查询中引入一些but。
所以我想知道:我该如何让这个:=起作用,或者用类似的东西来取代它呢?
编辑:
我发现了INTO关键字,现在我的查询如下所示。仍然说我有一个语法错误...
CREATE PROCEDURE select_buy(
IN buying BIGINT UNSIGNED,
IN buying_with BIGINT UNSIGNED,
IN quantity BIGINT UNSIGNED,
INOUT ttl BIGINT UNSIGNED
)
BEGIN
SELECT NULL AS price, NULL AS account_id, NULL as max_amount, NULL as total
FROM sellers
UNION ALL
SELECT price, account_id, max_amount, (SELECT (ttl + max_amount) INTO ttl) AS total
FROM (SELECT * FROM sellers ORDER BY price ASC) C where selling_currency_id = buying and buying_currency_id = buying_with and ttl < quantity
END发布于 2020-09-17 06:10:22
我的代码不能与@total一起工作,因为我没有重置@total (尽管它看起来很像)。我添加了SET @total = 0,现在一切都正常了。
https://stackoverflow.com/questions/63926656
复制相似问题