gpt4 book ai didi

mysql - 为什么这个存储过程在查询本身不返回多行时返回多行?

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:02 25 4
gpt4 key购买 nike

<分区>

我有一个 MySQL 8 服务器。我可以运行此查询来获取单行数据:

        SELECT *, CountOfSeconds/total AS GlobalTimer,
IF(CorrectAnswer = 'A', CountOfA/total,
IF(CorrectAnswer = 'B', CountOfB/total,
IF(CorrectAnswer = 'C', CountOfC/total,
IF(CorrectAnswer = 'D', CountOfD/total,
IF(CorrectAnswer = 'E', CountOfE/total, NULL )
)
)
)
) AS GlobalAccuracy
FROM(
SELECT *, (CountOfA+CountOfB+CountOfC+CountOfD+CountOfE) AS total
FROM mydb.questions WHERE QID=6522
)AS tbl

但是当我把它变成如下所示的存储过程时:

DELIMITER $$
USE `mydb`$$

DROP PROCEDURE IF EXISTS `QuestionDetails`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `QuestionDetails`(
IN qid INT(11)
)
BEGIN
SELECT *, CountOfSeconds/total AS GlobalTimer,
IF(CorrectAnswer = 'A', CountOfA/total,
IF(CorrectAnswer = 'B', CountOfB/total,
IF(CorrectAnswer = 'C', CountOfC/total,
IF(CorrectAnswer = 'D', CountOfD/total,
IF(CorrectAnswer = 'E', CountOfE/total, NULL )
)
)
)
) AS GlobalAccuracy
FROM(
SELECT *, (CountOfA+CountOfB+CountOfC+CountOfD+CountOfE) AS total
FROM questions WHERE QID=qid
)AS tbl;
END$$

DELIMITER ;

然后我得到与 questions 表中存在的行一样多的行。怎么会这样?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com