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
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
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
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
b is the alias for query result a and it definitely does not exist in where