0

我正在尝试编写一个程序来找到一类舰艇的火力。(火力是火炮数量*排量的立方)

关系:

Classes(class, type, country, numGuns, bore, displacement)

到目前为止我尝试过的...

CREATE PRODCEDURE firePower(in className VARCHAR(50), out p int)
-> begin
-> set p = (SELECT numGuns FROM classes WHERE class = className) * (SELECT displacement
FROM classes WHERE class = className)* (SELECT displacement FROM classes WHERE class
className)
-> * (SELECT displacement FROM classes WHERE class = className)
-> )
-> end;
-> //
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'PRODCEDURE
firePower(in className VARCHAR(50), out p int)
begin
set p = (SELECT ' at line 1

我知道这是一个可怕的查询。我不是在寻找性能,只是想让它正常工作。

4

2 回答 2

1

The first issue that sticks out to me is that you mispelled "PROCEDURE":

CREATE PRODCEDURE ...

should be

CREATE PROCEDURE ...
于 2012-04-23T17:10:54.747 回答
0

不是答案,但在评论中不起作用:

你为什么要做所有这些子选择?您正在使用相同的 where 子句从同一个表中获取不同的字段,您可以简单地执行以下操作:

SELECT numGuns * displacement * displacement * displacement
FROM classes
WHERE class = className
于 2012-04-23T17:19:32.550 回答