我做了以下过程,基本上是将两列中的一列“ not_good and good ”中的值传递到同一个表中的“ comment ”列,并使用等级值:
DELIMITER $$ CREATE OR REPLACE PROCEDURE add_comments() BEGIN DECLARE var INT; SELECT grade INTO var FROM table2; IF (var <= 7) THEN UPDATE table2 set comment = not_good; ELSE UPDATE table2 set comment = good; END IF; END$$ DELIMITER ;当我CALL add_comentarios(); 我收到以下错误:
#1172 - Result consisted of more than one row无法弄清楚如何使其工作,因为我想
PS:我是一个begginer rsrs
非常感谢任何答案!
I have the following procedure that I made to basically transfer the values from one of the two columns "not_good and good" to the column "comment" in the same table using the grade value:
DELIMITER $$ CREATE OR REPLACE PROCEDURE add_comments() BEGIN DECLARE var INT; SELECT grade INTO var FROM table2; IF (var <= 7) THEN UPDATE table2 set comment = not_good; ELSE UPDATE table2 set comment = good; END IF; END$$ DELIMITER ;When I CALL add_comentarios(); I receive the following error:
#1172 - Result consisted of more than one rowCan't figure out how to make it work as I want
PS: I'm a begginer rsrs
Thanks a lot for any answer!
最满意答案
SELECT X INTO Y查询仅对单个结果查询有效; 由于您的查询从整个表中选择,因此只有当该表具有单个行时才有效。 无论如何,你正在试图做的事情可以用单个查询来完成....
UPDATE table2 SET comment = CASE WHEN grade <= 7 THEN 'not_good' ELSE 'good' END ;SELECT X INTO Y queries are only valid for single result queries; since your query selects from the whole table, it would only be valid if the table had a single row. What you are trying to do can be done with a single query anyway....
UPDATE table2 SET comment = CASE WHEN grade <= 7 THEN 'not_good' ELSE 'good' END ;更多推荐
发布评论