子查询返回多于 1 行/指数移动平均值
CREATE DEFINER = `ninja_dba`@`` PROCEDURE `adb`.`MACD12`( x int)
LANGUAGE SQL
DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
COMMENT ''
BEGIN
MACD_12:BEGIN
DECLARE z FLOAT;
DECLARE y FLOAT default 56.41;
DECLARE w float;
WHILE x < 10 do
INSERT into `MACD`(
x,y,z,X12) select z,y,x,w;
SET z= IFNULL ( (y + ((2/13) * (w - y))),Y) ;
SET y=z;
SET x =x+1;
SET w = (select close from`raw data`);
end while;
end MACD_12;
END
call macd12 (1);
我正在尝试构建指数移动平均线。问题的一部分是设置第一行,因此我在程序开始时声明第一行(56.41)。我相信该过程会起作用,但是当我尝试调用该过程时,我收到臭名昭著的错误“子查询返回超过 1 行”错误 1242。
非常感谢任何帮助。
CREATE DEFINER = `ninja_dba`@`` PROCEDURE `adb`.`MACD12`( x int)
LANGUAGE SQL
DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
COMMENT ''
BEGIN
MACD_12:BEGIN
DECLARE z FLOAT;
DECLARE y FLOAT default 56.41;
DECLARE w float;
WHILE x < 10 do
INSERT into `MACD`(
x,y,z,X12) select z,y,x,w;
SET z= IFNULL ( (y + ((2/13) * (w - y))),Y) ;
SET y=z;
SET x =x+1;
SET w = (select close from`raw data`);
end while;
end MACD_12;
END
call macd12 (1);
I'm trying to construct a Exponential moving Average. Part of the problem is setting the first row, hence I declare the first row (56.41) as the procedure begins. I believe the procedure will work, however when I try to call the procedure, I get the infamous error "Subquery returns more than 1 row" error 1242.
Any assistance is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的问题在于
原始数据似乎超过 1 行,这就是可能发生错误的地方。
您需要指定条件(
WHERE
子句),或使用LIMIT
语句。I think your issue lies with
It would seem that
raw data
has more that 1 row, and this is where the error is likely to occur.You need to either specify a criteria (
WHERE
clause), or use aLIMIT
statement.的末尾。
如果将 LIMIT 1 放在“是否可以正常工作?”
If you put a LIMIT 1 on the end of
Does it work without errors?