比如SELECT a AS b WHRER b=1;
我这样使用会报错,说b不存在。
迷茫2017-04-17 15:38:18
Because when running SQL statements at the bottom of mysql: the filtering conditions after where come first, and the alias of as B comes after.
So when the machine sees the alias after where, it does not recognize it, so it will report that B does not exist.
If you must use B as the filter condition:
Solution: Nest another layer outside.
select * from
(
select A as B from table
) t
where t.B = XXX -- arbitrary filter conditions
If there is no nesting, you can only use A as the filter condition
大家讲道理2017-04-17 15:38:18
Of course it does not exist, this b is only for an alias with the query result of a
select a AS b FROM table where a = 1
巴扎黑2017-04-17 15:38:18
select t.b from
(
select a as B from table
) t
where t.b =xxxx
B at this time can be used directly in where
巴扎黑2017-04-17 15:38:18
b is the alias for query result a and it definitely does not exist in where