如何对sql别名进行操作
我有这么一条sql语句
select a.id,a.name,a.renshu,(select isnull(sum(b.fs),0) from b where b.reid=a.id) as 总分数a,(select isnull(sum(c.fs),0) from c where c.reid=a.id) as 总分数c, (总分数a+总分数c)/a.renshu as pjfs where a.del=0
上面这条语句红色部分删掉语句就可以运行,也就是不能使用别名再进行运算,我应该怎么才能使别名运算呢?
------解决方案--------------------
再加一层嵌套
select a.*,(a.总分数a+a.总分数c)/a.renshu as pjfs from (select a.id,a.name,a.renshu,(select isnull(sum(b.fs),0) from b where b.reid=a.id) as 总分数a,(select isnull(sum(c.fs),0) from c where c.reid=a.id) as 总分数c where a.del=0) a