Using column alias in WHERE clause of MySQL query produces an error

后端 未结 8 1088
北荒
北荒 2020-11-22 03:40

The query I\'m running is as follows, however I\'m getting this error:

#1054 - Unknown column \'guaranteed_postcode\' in \'IN/ALL/ANY subquery\'

<
相关标签:
8条回答
  • 2020-11-22 04:14

    You can use HAVING clause for filter calculated in SELECT fields and aliases

    0 讨论(0)
  • 2020-11-22 04:14

    Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined. For example, the following query is illegal:

    SELECT id, COUNT(*) AS cnt FROM tbl_name WHERE cnt > 0 GROUP BY id;

    0 讨论(0)
提交回复
热议问题