我需要兩個結合兩個查詢才能得到一個結果。這是第一個代碼。如何結合兩個查詢來獲得一個結果?
SELECT FKLTI_KTRGN, COUNT(DISTINCT VIEW_PELAJAR_ENROLL.MB_NAMA) AS BIL_UG
FROM VIEW_PELAJAR_ENROLL, KOD_BANGSA, KOD_NEGERI, JANTINA, KOD_AGAMA, KOD_CACAT, TARAF_KAHWIN
WHERE KOD_KTRGN_PROGRAM = 'SARJANA MUDA'
AND MS_SESI = '2015/2016'
AND MB_BANGSA = KOD_BANGSA
AND KOD_NEGERI = MB_ASAL
AND MB_JANTINA = JAN_KOD
AND KOD_AGAMA = MB_AGAMA
AND KOD_CACAT = MB_CACAT
AND KOD_TARAF = MB_TARAF_KAHWIN
AND MS_STATUS_SEMASA IN
(SELECT SP_KOD
FROM STATUS_PELAJAR
WHERE STATUS_ENROLL = 'Y'
AND SP_TAMAT IS NULL
AND SP_KOD = MS_STATUS_SEMASA)
GROUP BY FKLTI_KTRGN
這是第二個代碼。
SELECT FKLTI_KTRGN, COUNT(DISTINCT PELAJAR_BIODATA.MBUT_NAMA) AS BIL_PG
FROM PELAJAR_BIODATA,KOD_NEGERI,FAKULTI,KOD_IJAZAH,PELAJAR_BUTIR_PENGAJIAN,STATUS_PENGAJIAN A,
KOD_STATUS_PELAJAR_IPS, KOD_CACAT, KOD_BANGSA, E_KOD_PENGAJIAN, JANTINA, KOD_PROGRAM
WHERE A.STAT_STATUS IN (SELECT KOD_STATUS
FROM KOD_STATUS_PELAJAR_IPS
WHERE STATUS_ENROLL='Y'
AND KOD_STATUS=STAT_STATUS)
AND A.STAT_NOMKPB=MBUT_NOMKPB
AND PBP_PROGRAM IN ('5','6')
AND MBUT_ASAL=KOD_NEGERI(+)
AND SUBSTR(A.STAT_KOD_IJAZAH,1,1)=FKLTI_KOD
AND PBP_PROGRAM=KOD_PROGRAM.KOD_PROGRAM
AND A.STAT_KOD_IJAZAH=KOD_IJAZAH_UM
AND A.STAT_NODAFTAR=PBP_NODAFTAR
AND MBUT_CACAT=KOD_CACAT
AND KOD_BANGSA=MBUT_BANGSA
AND PBP_JENIS_PENGAJIAN=KOD_JNS_PENGAJIAN
AND MBUT_JANTINA=JAN_KOD
AND MBUT_WARGA IS NOT NULL
AND MBUT_BANGSA IS NOT NULL
AND MBUT_JANTINA IS NOT NULL
AND MBUT_NEGERI IS NOT NULL
AND PBP_PROGRAM IS NOT NULL
AND A.STAT_STATUS=KOD_STATUS
AND PBP_KOD_IJAZAH IS NOT NULL
AND A.STAT_SESI||A.STAT_SEMESTER IN (SELECT MAX(B.STAT_SESI||B.STAT_SEMESTER) FROM STATUS_PENGAJIAN B
WHERE B.STAT_NODAFTAR=A.STAT_NODAFTAR
AND B.STAT_NOMKPB=A.STAT_NOMKPB
AND A.STAT_SESI||A.STAT_SEMESTER=B.STAT_SESI||B.STAT_SEMESTER)
AND A.STAT_SESI = '2015/2016'
group by FKLTI_KTRGN
這是預期的結果:
這就是我得到:
我試着使用UNION,但它不工作。任何人都可以幫助我?我真的需要你的幫助。先謝謝你!
究竟是如何'union'不爲你工作?兩個查詢都返回兩個相同類型的列 - 所以union *應該可以工作。 –
聯盟應該工作,你得到了什麼錯誤?但是,你想要什麼,你能顯示每個查詢的樣本輸出,以及這些樣本輸出的預期結果嗎? –
爲每個查詢添加示例結果,並向我們展示組合結果以及所有格式化文本! – jarlh