如何实现查询结果的字段再引用?
rt
举例:a、b、c、d、e为table其中5列
select a+b+c+d as c1,c1+e as c2 from table
这样子出错,怎样才能引用到新列c1,不想用a+b+c+d+e as c2 这样太麻烦了
------解决方案--------------------SELECT c1,c1 + e as c2
FROM
(select a+b+c+d as c1,e from table) AS t
------解决方案--------------------1楼显然能解决你的问题
但注意,子查询的写法有可能影响性能,a+b+c+d+e as c2 的写法实际并不麻烦,具体取舍自己考虑
------解决方案----------------------用子查询
SELECT c1,c1 + e as c2
FROM (select a+b+c+d as c1,e from table) AS t
--或,将公式拆分到最原始的字段
select a+b+c+d as c1, a+b+c+d+e
from table
------解决方案--------------------a+b+c+d+e as c2 才是最简单的,而且速度也快
------解决方案--------------------错误的方法有好多种,只需要记住一种最好的就好了.