结果多于一行(More than one row as result)

编程入门 行业动态 更新时间:2024-10-10 15:21:32
结果多于一行(More than one row as result)

我做了以下过程,基本上是将两列中的一列“ 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 row

Can'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 ;

更多推荐

本文发布于:2023-04-29 08:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:row   result

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!