如何使用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
答案 0 :(得分: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
答案 1 :(得分: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