我有一个声明,我想在我的sql语句中使用别名的值。我该怎么用呢?有没有可能的方法来使用别名值。
SELECT ORDERID ,clientnum,ID, READYDATE,
case when ID=56 then 'O'
ELSE
CASE when ID=65 then 'A'
ELSE
'NONE'
END
END
AS LOctaion -- want to use this alias below in where clause
from orde_
where READYDATE='2014-05-09' AND LOctaion='A'
这有可能我怎么做到这一点。感谢您的评论
答案 0 :(得分:2)
你可以这样做:
SELECT
*
FROM
(
SELECT
ORDERID ,
clientnum,
ID,
READYDATE,
(
case when ID=56 then 'O'
ELSE
CASE when ID=65 then 'A'
ELSE
'NONE'
END
END) AS LOctaion
from orde_
) AS tbl
where tbl.READYDATE='2014-05-09' AND tbl.LOctaion='A'