Understanding Oracle aliasing - why isn't an alias not recognized in a query unless wrapped in a second query?

后端 未结 4 1229
我寻月下人不归
我寻月下人不归 2020-12-07 01:38

I have a query


SELECT COUNT(*) AS \"CNT\",
       imei
FROM   devices  

which executes just fine. I want to further restrict the query wi

4条回答
  •  感动是毒
    2020-12-07 02:15

    Because the documentation says it won't:

    Specify an alias for the column expression. Oracle Database will use this alias in the column heading of the result set. The AS keyword is optional. The alias effectively renames the select list item for the duration of the query. The alias can be used in the order_by_clause but not other clauses in the query.

    However, when you have an inner select, that is like creating an inline view where the column aliases take effect, so you are able to use that in the outer level.

提交回复
热议问题