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

后端 未结 4 1222
我寻月下人不归
我寻月下人不归 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:10

    The simple answer is that the AS clause defines what the column will be called in the result, which is a different scope than the query itself.

    In your example, using the HAVING clause would work best:

    SELECT COUNT(*) AS "CNT",
           imei
    FROM   devices
    GROUP  BY imei
    HAVING COUNT(*) > 1
    

提交回复
热议问题