日期:2014-05-17  浏览次数:20433 次

sql中附加的字段怎么进行操作
select aaa_id,aaa_name,aaa_value,(select sum(bbb_value) from bbb where bbb_id=aaa_reid) as bbb_value,aaa_value/bbb_value as ccc from aaa 


aaa_value/bbb_value as ccc 这个地方无法使用 bbb_value

 应该怎么才能使用这个附加的字段呢

------解决方案--------------------
SQL code
--不能直接使用,换个方式
select aaa_id,aaa_name,aaa_value,bbb_value,aaa_value/bbb_value as ccc from
(
    select aaa_id,aaa_name,aaa_value,(select sum(bbb_value) from bbb where bbb_id=aaa_reid) as bbb_value from aaa  
) t
--or
select aaa_id,aaa_name,aaa_value,(select sum(bbb_value) from bbb where bbb_id=aaa_reid) as bbb_value,aaa_value/(select sum(bbb_value) from bbb where bbb_id=aaa_reid) as ccc 
from aaa