重複の可能性:
WHERE 句でのエイリアスの使用
以下のクエリの where 条件でエイリアス名を使用できない理由を教えてください..
SELECT * FROM (
SELECT USER_NAME AS "User ID",
OLD_VALUE_STRING as "Status",
NVL(lag(ENTRY_DATE) over (partition by user_name order by ENTRY_DATE), trunc(Sysdate-1)) as "Begin",
ENTRY_DATE as "End"
FROM (SELECT U.USER_NAME,
U.FULL_NAME,
UH.OLD_VALUE_STRING,
UH.NEW_VALUE_STRING,
UH.ENTRY_DATE,
US.IS_WORKING
FROM VIW.USER_HISTORY UH, VIW.USERS U, VIW.USER_STATUS US
WHERE U.ID = UH.USER_ID
AND UH.EVENT_ID = VIW.EVENT_PKG.GET_ID('UPD_USR_STATUS')
AND UH.NEW_VALUE_STRING = US.ABBREVIATION
AND UH.ENTRY_DATE >= TO_DATE('01082013', 'MMDDYYYY')
AND UH.ENTRY_DATE <= TO_DATE('01092013', 'MMDDYYYY')
ORDER BY U.USER_NAME, UH.ENTRY_DATE)
UNION
SELECT USER_NAME AS "User ID",
NEW_VALUE_STRING as "Status",
ENTRY_DATE AS "Begin",
lead(ENTRY_DATE) over (partition by user_name order by ENTRY_DATE) as "End"
FROM (SELECT U.USER_NAME,
U.FULL_NAME,
UH.OLD_VALUE_STRING,
UH.NEW_VALUE_STRING,
UH.ENTRY_DATE,
US.IS_WORKING
FROM VIW.USER_HISTORY UH, VIW.USERS U, VIW.USER_STATUS US
WHERE U.ID = UH.USER_ID
AND UH.EVENT_ID = VIW.EVENT_PKG.GET_ID('UPD_USR_STATUS')
AND UH.NEW_VALUE_STRING = US.ABBREVIATION
AND UH.ENTRY_DATE >= TO_DATE('01082013', 'MMDDYYYY')
AND UH.ENTRY_DATE <= TO_DATE('01092013', 'MMDDYYYY')
ORDER BY U.USER_NAME, UH.ENTRY_DATE)
) as innerTable
WHERE Status <>'LOGGED_OUT'
ORDER BY 1,3