当select和where块中使用相同的表达式时,postgresql中有没有办法不重复自己?
select (
|/(( power((consumption_2011 - consumption_3y/3), 2)
+ power((consumption_2012 - consumption_3y/3), 2)
+ power((consumption_2013 - consumption_3y/3), 2)
) / 3)) as deviation
from consumption
where (
|/(( power((consumption_2011 - consumption_3y/3), 2)
+ power((consumption_2012 - consumption_3y/3), 2)
+ power((consumption_2013 - consumption_3y/3), 2)
) / 3) > 0.8
)
答案 0 :(得分:3)
你可以这样做:
select deviation
from (
select
(( power((consumption_2011 - consumption_3y/3), 2)
+ power((consumption_2012 - consumption_3y/3), 2)
+ power((consumption_2013 - consumption_3y/3), 2)
) / 3) as deviation
from consumption) sub
where deviation > 0.8