try-- select a,b,[temp] = a+b from t where [temp]='xxx'
select a,b,temp = a+b from t where a+b='xxx'
-- select a,b,temp = a+b from t where a+b='xxx'
看错,用2楼的或者select a,b,temp = a+b from t where a+b='xxx'
说过N次了..SQL在内部的执行顺序大概是这样的 先执行FROM 如果有JOIN .而会先产生个迪卡尔积.. 然后再执行 WHERE.进行筛选.. 然后才执行 SELECT 进行投影..所以很清楚了..在 WHERE的时候..看不到 SELECT投影的别名..所以select a,b,temp = a+b from t where a+b='xxx' ORSELECT * FROM ( select a,b,temp = a+b from t ) AS T where temp='xxx'
可能要把temp的表达式在where后面写出来。语句复杂的话可以借助视图。
select id,lie1,lie2,[temp] = lie1+lie2 from t where lie1+lie2 = '3' 或者 select * from (select id,lie1,lie2,temp = lie1+lie2 from t) tt where temp='3'
select a,b,[temp] = a+b from t where [temp]='xxx'
select a,b,temp = a+b from t where a+b='xxx'
先执行FROM 如果有JOIN .而会先产生个迪卡尔积..
然后再执行 WHERE.进行筛选..
然后才执行 SELECT 进行投影..所以很清楚了..在 WHERE的时候..看不到 SELECT投影的别名..所以select a,b,temp = a+b from t where a+b='xxx' ORSELECT *
FROM
(
select a,b,temp = a+b from t
) AS T
where temp='xxx'
或者
select * from (select id,lie1,lie2,temp = lie1+lie2 from t) tt where temp='3'
真可惜,不过谢谢你,你的解释让我完全明白了问题的所在。