Please, I do not understand why it is not working:
拜托,我不明白为什么它不起作用:
SET @key = (SELECT customer.key_stamp FROM customer WHERE customer.key_stamp = "0000");
CASE WHEN (@key > 0) THEN
INSERT INTO transaction
(transaction.to, transaction.key, transaction.type, transaction.cost_bitcoin, transaction.quantity)
VALUES ("0000", "f5rwsd", 2, 0.0075,
(500000 +
(
(SELECT bonus.amount
FROM bonus
WHERE 500000 BETWEEN bonus.min_quantity AND bonus.max_quantity
) / 500000
) * 100))
END;
I tried the CASE STATEMENT, but it still does not work, and i can't understand the issue. Please help.
我尝试过CASE STATEMENT,但它仍然不起作用,我无法理解这个问题。请帮忙。
2 个解决方案
#1
1
CASE
is not a valid MySQL statement. (It's not a valid statement outside the context of a MySQL stored program.)
CASE不是有效的MySQL语句。 (它不是MySQL存储程序上下文之外的有效语句。)
"Why it is not work"... is because it's not valid SQL.
“为什么它不起作用”......是因为它不是有效的SQL。
A CASE
expression can be used in a SQL statement where an expression is allowed. (In SQL, an expression returns a value of a particular datatype.)
CASE表达式可以在允许表达式的SQL语句中使用。 (在SQL中,表达式返回特定数据类型的值。)
As an example of using a CASE
expression in a SQL statement, something like this:
作为在SQL语句中使用CASE表达式的示例,如下所示:
SELECT CASE WHEN @key > 0 THEN 'somevalue' ELSE 'othervalue' END AS foo
#2
1
in fact now i use just an sql functions, and it work now, all work, switch case mysql, if else statement mysql, and loops too, like while do, or LOOP ITERATE, all work, just need use it in sql functions, or sql procedure.
事实上现在我只使用一个sql函数,它现在工作,所有工作,切换案例mysql,if else语句mysql,以及循环,就像do do,或LOOP ITERATE,所有工作,只需要在sql函数中使用它,或者sql程序。
#1
1
CASE
is not a valid MySQL statement. (It's not a valid statement outside the context of a MySQL stored program.)
CASE不是有效的MySQL语句。 (它不是MySQL存储程序上下文之外的有效语句。)
"Why it is not work"... is because it's not valid SQL.
“为什么它不起作用”......是因为它不是有效的SQL。
A CASE
expression can be used in a SQL statement where an expression is allowed. (In SQL, an expression returns a value of a particular datatype.)
CASE表达式可以在允许表达式的SQL语句中使用。 (在SQL中,表达式返回特定数据类型的值。)
As an example of using a CASE
expression in a SQL statement, something like this:
作为在SQL语句中使用CASE表达式的示例,如下所示:
SELECT CASE WHEN @key > 0 THEN 'somevalue' ELSE 'othervalue' END AS foo
#2
1
in fact now i use just an sql functions, and it work now, all work, switch case mysql, if else statement mysql, and loops too, like while do, or LOOP ITERATE, all work, just need use it in sql functions, or sql procedure.
事实上现在我只使用一个sql函数,它现在工作,所有工作,切换案例mysql,if else语句mysql,以及循环,就像do do,或LOOP ITERATE,所有工作,只需要在sql函数中使用它,或者sql程序。