在MySQL查询的WHERE子句中使用列别名会产生错误我正在运行的查询如下所示,但是我得到了这个错误:#1054-‘IN/All/ANY子查询’中未知列‘已保证的_邮政编码’SELECT `users`.`first_name`, `users`.`last_name`, `users`.`email`,SUBSTRING(`locations`.`raw`,-6,4) AS `guaranteed_postcode`FROM `users` LEFT OUTER JOIN `locations`ON `users`.`id` = `locations`.`user_id`WHERE `guaranteed_postcode` NOT IN #this is where the fake col is being used(
SELECT `postcode` FROM `postcodes` WHERE `region` IN
(
'australia'
))我的问题是:为什么我不能在同一DB查询的WHERE子句中使用假列?
3 回答
慕娘9325324
TA贡献1783条经验 获得超4个赞
SELECT `users`.`first_name`,`users`.`last_name`,`users`.`email`,SUBSTRING(`locations`.`raw`,-6,4) AS `guaranteed_postcode`FROM `users` LEFT OUTER JOIN `locations`ON `users`.`id` = `locations`.`user_id`WHERE SUBSTRING(`locations`.`raw`,-6,4) NOT IN #this is where the fake col is being used( SELECT `postcode` FROM `postcodes` WHERE `region` IN ( 'australia' ))
添加回答
举报
0/150
提交
取消