当前位置: 代码迷 >> Sql Server >> sql中附加的字段如何进行操作
  详细解决方案

sql中附加的字段如何进行操作

热度:97   发布时间:2016-04-27 11:23:20.0
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--orselect 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
  相关解决方案