0

我只是尝试以下查询:

CREATE DEFINER=`root`@`localhost` FUNCTION `cal1`(z DATE , y DATE) RETURNS float
BEGIN
SET @c= (SELECT a.StudentName, (b.marks/a.marks) as difference from (select Date, StudentName, marks from studenthistory2015 WHERE Date=z) as a INNER JOIN (select Date, StudentName, marks from studenthistory2015 where Date=y) as b on a.date=z and b.date=y WHERE a.date = z and b.date = y and a.StudentName=b.StudentName
);
RETURN @c;
END

执行 :

选择 student_history.cal1('2015-01-01', '2015-02-01'); 但执行后,它显示错误 #1241 操作数应包含 1 列

我应该如何解决这个查询?

4

1 回答 1

0

正如P.Salmon所说,您正在尝试返回一组参数,其中包含字符串和浮点数(我假设)

SELECT a.StudentName, (b.marks/a.marks) as difference

而不是返回单个变量,尽管您实际上确实在函数中声明了您将返回一个浮点数:RETURNS float

也许您可以将您的功能转换为一个过程,就像这里的详细答案中提到的那样,回答与您相关的另一个问题。

于 2017-11-21T09:31:56.777 回答