如何将sysdate列添加到包含左外连接的查询

时间:2016-07-11 13:07:19

标签: sql oracle left-join

我需要一些帮助,在我的查询中添加一列,用作“提取日期”列。 我的原始查询看起来像:

SELECT 
PR.PARENT_ID,
PR.ID as Record_ID,   
PROJECT.NAME as Project_Name,
PR_STATUS_TYPE.NAME  as RECORD_State, 
PERSON_RELATION.NAME as ORIGINATOR,
PR.DATE_OPENED, 
TW_V_AUDIT.S_VALUE as aud,
PR.NAME TITLE
FROM (PR PR 
LEFT OUTER JOIN PROJECT PROJECT ON PR.PROJECT_ID=PROJECT.ID) 
LEFT OUTER JOIN PERSON_RELATION ON PERSON_RELATION.ID = PR.ORIGINATOR_REL_ID
LEFT OUTER JOIN PR_STATUS_TYPE PR_STATUS_TYPE ON PR.STATUS_TYPE=PR_STATUS_TYPE.ID
LEFT OUTER JOIN TW_V_AUDIT ON TW_V_AUDIT.PR_ID = PR.ID
WHERE  
PROJECT.NAME='Audit' 
GROUP BY
PERSON_RELATION.NAME,
PR.ID, 
PR.PARENT_ID,
PROJECT.NAME,
PR_STATUS_TYPE.NAME,
PR.DATE_OPENED,
TW_V_AUDIT.S_VALUE,
PR.NAME
ORDER BY
RECORD_ID;

我希望添加一个显示系统日期的列,该列是以下查询:

Select TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') from dual

我该怎么办?我正在使用sql developer。 如果我需要更多信息,请告诉我。 再次感谢大家。

桑尼

2 个答案:

答案 0 :(得分:1)

只需添加此部分:

TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') as System_Date

到您的SELECT列表

答案 1 :(得分:1)

只需将日期列添加到您的Select Statement:

SELECT 
PR.PARENT_ID,
PR.ID as Record_ID,   
PROJECT.NAME as Project_Name,
PR_STATUS_TYPE.NAME  as RECORD_State, 
PERSON_RELATION.NAME as ORIGINATOR,
PR.DATE_OPENED, 
TW_V_AUDIT.S_VALUE as aud,
PR.NAME TITLE,
TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') as date
FROM (PR PR 
LEFT OUTER JOIN PROJECT PROJECT ON PR.PROJECT_ID=PROJECT.ID) 
LEFT OUTER JOIN PERSON_RELATION ON PERSON_RELATION.ID = PR.ORIGINATOR_REL_ID
LEFT OUTER JOIN PR_STATUS_TYPE PR_STATUS_TYPE ON PR.STATUS_TYPE=PR_STATUS_TYPE.ID
LEFT OUTER JOIN TW_V_AUDIT ON TW_V_AUDIT.PR_ID = PR.ID
WHERE  
PROJECT.NAME='Audit' 
GROUP BY
PERSON_RELATION.NAME,
PR.ID, 
PR.PARENT_ID,
PROJECT.NAME,
PR_STATUS_TYPE.NAME,
PR.DATE_OPENED,
TW_V_AUDIT.S_VALUE,
PR.NAME
ORDER BY
RECORD_ID;