子查询返回多于 1 行/指数移动平均值

发布于 2024-10-10 06:35:14 字数 608 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极度宠爱 2024-10-17 06:35:14

我认为你的问题在于

SET w = (select close from`raw data`);

原始数据似乎超过 1 行,这就是可能发生错误的地方。

您需要指定条件(WHERE 子句),或使用 LIMIT 语句。

I think your issue lies with

SET w = (select close from`raw data`);

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 a LIMIT statement.

々眼睛长脚气 2024-10-17 06:35:14

的末尾。

SET w = (select close from`raw data`); 

如果将 LIMIT 1 放在“是否可以正常工作?”

If you put a LIMIT 1 on the end of

SET w = (select close from`raw data`); 

Does it work without errors?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文