简体   繁体   English

从其他计算字段中计算出的Mysql归档

[英]Filed in Mysql calculated from other calculated fields

I seek a way to be able to write something like this 我寻求一种方法来写这样的东西

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

rather than writing it in the far more complicated way like this 而不是像这样复杂得多

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

Is this possible? 这可能吗?

Not in the same line. 不在同一行。

What you can do is: 您可以做的是:

SELECT comp1, comp2, (comp1/comp2) as percent FROM(
select complicated_calculation1 as comp1, 
complicated_calculation2 as comp2
from table) AS t
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM