0

我如何使用 mysql 查询选择像这样的等式( decimalnumber_1 / (100+decimalnumber_2) * 100 )

decimalnumber_1 = //SELECT table_1.a_decimalnumber_1 AS decimalnumber_1 FROM table_1 WHERE table_1.another_coloumn_name = z

decimalnumber_2 = //SELECT table_2.a_decimalnumber_2 AS decimalnumber_2 FROM table_2 WHERE table_2.an_another_coloumn_name = x

result =  //SELECT ( decimalnumber_1 / (100+decimalnumber_2) * 100 ) AS result
4

2 回答 2

1
CREATE PROCEDURE @eqresult 
@result int output
AS
DECLARE @decNum1 int,@decNum2 int 
SET @decNum1=(SELECT table_1.a_decimalnumber_1 AS decimalnumber_1 FROM table_1 
             WHERE  table_1.another_coloumn_name = z)
SET @decNum1=(SELECT table_2.a_decimalnumber_2 AS decimalnumber_2 FROM table_2 
             WHERE  table_2.another_coloumn_name = x)
SET @result=( @decNum1 / (100+@decNum2) * 100 )
RETURN @result
于 2012-04-26T09:04:04.780 回答
0

尝试

SELECT ( (SELECT table_1.a_decimalnumber_1 AS decimalnumber_1 FROM table_1 WHERE table_1.another_coloumn_name = z
)/ (100+(SELECT table_2.a_decimalnumber_2 AS decimalnumber_2 FROM table_2 WHERE table_2.an_another_coloumn_name = x
)) * 100 ) AS result
于 2012-04-26T08:41:55.040 回答