迷茫2017-04-17 15:38:18
因為mysql底層跑SQL語句時:where 後的篩選條件在先,as B的別名在後。
所以機器看到where 後的別名是不認的,所以會報說B不存在。
如果要用B做篩選條件的話:
解:外邊再嵌套一層。
select * from
(
select A as B from table
) t
where t.B = XXX -- 任意的篩選條件
如果不嵌套,只能用A做篩選條件了
巴扎黑2017-04-17 15:38:18
select t.b from
(
select a as B from table
) t
where t.b =xxxx
此時的B是可以直接在where中使用的