我需要创建视图,我基本上必须将三个表组合在一起才能查看联系人上次验证的时间。这是我到目前为止的代码:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW
LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE VERIFIED_ON IS NULL OR
VERIFIED_ON > SYSDATE-365
ORDER BY LASTNAME;
我不断收到此错误,无法弄清楚原因。
Error at Command Line:10 Column:7
Error report:
SQL Error: ORA-00904: "VERIFIED_ON": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
如果有人能提供帮助,我会非常感激。
答案 0 :(得分:1)
您在verified_on
子句中使用where
。我认为你需要last_date_verified
代替:
CREATE VIEW P_PHONECONTACT_VERIFICATION_V AS
SELECT
OW.LASTNAME, OW.FIRSTNAME, OW.EMAIL,
OP.PHONE_CONTACTID, OP.PHONENUM, OP.PHONETYPE,
OC.LAST_DATE_VERIFIED AS VERIFIED_ON
FROM P_OWNER OW LEFT JOIN P_OWNERCONTACT OC
ON OW.OWNERID = OC.OWNERID
LEFT JOIN P_OWNERPHONE OP
ON OC.CONTACTID = OP.PHONE_CONTACTID
WHERE OC.LAST_DATE_VERIFIED IS NULL OR
OC.LAST_DATE_VERIFIED > SYSDATE-365
ORDER BY LASTNAME;
您不能使用select
子句中where
子句中定义的列别名。