MYSQL中如何把SELECT A AS B中的B作为WHERE筛选条件
PHPz
PHPz 2017-04-17 15:36:18
0
4
632

比如SELECT a AS b WHRER b=1;

我这样使用会报错,说b不存在。

PHPz
PHPz

学习是最好的投资!

reply all(4)
迷茫

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!