我目前在这里使用 oracle 11g 是我面临的问题。我有一个 SQL 语句显示如下:
SELECT A.LM_PERSON_ID
,A.LM_GRADE
,C.COURSE_STR
,Decode (A.LM_GRADE,'001','1','002','2','003','3') AS JOB_GRADE
FROM PS_LM_PERSON_JOB A
,PS_LM_LPLN_LRN B
,PS_LM_LPLN_DTL C
,PS_LM_ENRLMT D
,PS_LM_CI_TBL E
WHERE A.LM_EMPL_RCD='0'
AND A.LM_EFFSEQ=(SELECT Max(A1.LM_EFFSEQ) FROM PS_LM_PERSON_JOB A1
WHERE A.LM_PERSON_ID=A1.LM_PERSON_ID AND A.EFFDT=A1.EFFDT
AND A.LM_EMPL_RCD=A1.LM_EMPL_RCD)
AND A.LM_ACTIVE='Y'
AND A.EFFDT=(SELECT Max(A2.EFFDT) FROM PS_LM_PERSON_JOB A2
WHERE A.LM_PERSON_ID=A2.LM_PERSON_ID AND A.LM_EMPL_RCD=A2.LM_EMPL_RCD
AND A.LM_EFFSEQ=A2.LM_EFFSEQ)
AND A.LM_PERSON_ID=B.LM_PERSON_ID (+)
AND B.LM_LPLN_ID=C.LM_LPLN_ID (+)
AND B.LM_PERSON_ID=C.LM_PERSON_ID (+)
AND C.LM_ENRLMT_ID=D.LM_ENRLMT_ID (+)
AND D.LM_CI_ID=E.LM_CI_ID (+)
AND E.EFFDT=(SELECT Max(E1.EFFDT) FROM PS_LM_CI_TBL E1 WHERE E.LM_CI_ID=E1.LM_CI_ID)
ORDER BY A.LM_PERSON_ID
我想要的输出是:
JOB GRADE COURSE_STR.A COURSE_STR.B COURSE_STR.C
1 5 3 1
2 4 2 2
3 1 1 1
有人可以分享你是如何做到的吗?非常感谢你。