简体   繁体   English

错误#1241操作数在Mysqlworkbench中应包含1列

[英]Error #1241 Operand should contain 1 column(s) in Mysqlworkbench

I just try following query: 我只是尝试以下查询:

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

Execution : 执行:

select student_history.cal1('2015-01-01', '2015-02-01'); 选择student_history.cal1('2015-01-01','2015-02-01'); But after execution, it shows Error #1241 Operand should contain 1 column(s) 但是执行后,它显示错误#1241操作数应包含1列

How should I resolve this query? 我应该如何解决这个查询?

As P.Salmon said, you are trying to return a set of params, containing both strings and floats (i assume) 正如P.Salmon所说,您正在尝试返回一组包含字符串和浮点数的参数(我认为)

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

instead of returning a single variable, although you actually did declare, in your function, that you will return a float: RETURNS float 尽管实际上已经在函数中声明了,而不是返回单个变量,但是您将返回一个浮点数: RETURNS float

Maybe you can convert you function into a procedure, like mentioned in this detailed answer here , answering another question related to yours. 也许您可以将您的函数转换为一个过程,如此处的详细答案所述 ,回答与您的问题有关的另一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM