提交在Mysql中从其他计算字段计算

时间:2013-02-01 09:14:22

标签: mysql database

我寻求一种能够写出这样的东西的方法

select complicated_calculation1 as comp1, 
complicated_calculation2 as comp2, 
(comp1/comp2) as percent
from table

而不是像这样更复杂的方式写它

select complicated_calculation1 as comp1, 
complicated_calculation2 as comp2, 
(complicated_calculation1/complicated_calculation2) as percent
from table

这可能吗?

2 个答案:

答案 0 :(得分:0)

不在同一行。

你能做的是:

SELECT comp1, comp2, (comp1/comp2) as percent FROM(
select complicated_calculation1 as comp1, 
complicated_calculation2 as comp2
from table) AS t

答案 1 :(得分:0)

no u cann't use this 

select complicated_calculation1 as comp1, 
complicated_calculation2 as comp2, 
(comp1/comp2) as percent
from table

u have to use only this 

select complicated_calculation1 as comp1, 
complicated_calculation2 as comp2, 
(complicated_calculation1/complicated_calculation2) as percent
from table

because rantime calculation can not be applied on Alis field name