iT邦幫忙

0

把PASS跟Fail合併為一筆資料

  • 分享至 

  • xImage

請問,如何把PASS跟Fail合併為一筆資料https://ithelp.ithome.com.tw/upload/images/20190326/20116136BlFnuQtjhp.png
SELECT *
FROM (
(SELECT A.WORK_ORDER
,A.PALLET_NO
,A.SERIAL_NUMBER
,B.PROCESS_NAME
,'10'AS STEP
,'QC CODE'AS ACTION
,case
when A.OUT_PROCESS_TIME=C.REC_TIME or A.PROCESS_ID=F.RP_PROCESS_ID
then E.DEFECT_CODE
else 'PASS'
end as "DEFECT_CODE"
,case
when A.OUT_PROCESS_TIME=C.REC_TIME
then E.DEFECT_DESC
else null
end as "不良描述1"
,A.OUT_PROCESS_TIME "OutProcessTime"
,case
when A.OUT_PROCESS_TIME=C.REC_TIME
then F.REPAIR_TIME
else null
end as "(Repair Time)"
,Case
when A.OUT_PROCESS_TIME=C.REC_TIME or A.PROCESS_ID=F.RP_PROCESS_ID
then G.REASON_CODE
else null
end as "原因代碼(Reason Code)"
,case
when A.OUT_PROCESS_TIME=C.REC_TIME or A.PROCESS_ID=F.RP_PROCESS_ID
then G.REASON_DESC
else null
end as "原因描述(Reason Desc)"
,case
when A.OUT_PROCESS_TIME=C.REC_TIME or A.PROCESS_ID=F.RP_PROCESS_ID
then F.LOCATION
else null
end as "位置(Location)"
,case
when A.OUT_PROCESS_TIME=C.REC_TIME or A.PROCESS_ID=F.RP_PROCESS_ID
then H.DUTY_DESC
else null
end as "責任描述(DutyDesc)"
FROM SAJET.G_SN_TRAVEL A
,SAJET.SYS_PROCESS B
,SAJET.G_SN_DEFECT C
,SAJET.SYS_DEFECT E
,SAJET.G_SN_REPAIR F
,SAJET.SYS_REASON G
,SAJET.SYS_DUTY H
,SAJET.SYS_PART D
WHERE A.PROCESS_ID = B.PROCESS_ID
AND A.SERIAL_NUMBER=C.SERIAL_NUMBER
AND E.DEFECT_ID=C.DEFECT_ID
AND F.RECID=C.RECID
AND F.REASON_ID=G.REASON_ID
AND A.MODEL_ID = D.PART_ID
AND F.DUTY_ID=H.DUTY_ID
AND B.PROCESS_NAME not in 'MAC MAP'
AND B.PROCESS_NAME NOT LIKE ('%REPAIR%')
AND A.SERIAL_NUMBER ='IXJ147241' )
--AND A.WORK_ORDER ='100S-209104')
UNION
(SELECT DISTINCT A.WORK_ORDER
,A.PALLET_NO
,A.SERIAL_NUMBER
,B.PROCESS_NAME
,'10'AS STEP
,'QC CODE'AS ACTION
,case
when A.OUT_PROCESS_TIME=C.RECORD_TIME
then A.SSN
else 'PASS'
end as "DEFECT_CODE"
,null
,A.OUT_PROCESS_TIME
,null
,null
,null
,null
,null
FROM SAJET.G_SN_TRAVEL A
,SAJET.SYS_PROCESS B
,SAJET.G_BARCODE C
,SAJET.SYS_PART D
WHERE A.PROCESS_ID = B.PROCESS_ID
AND A.SERIAL_NUMBER=C.SERIAL_NUMBER
AND A.MODEL_ID = D.PART_ID
AND B.PROCESS_NAME not in 'MAC MAP'
AND B.PROCESS_NAME NOT LIKE ('%REPAIR%')
AND A.SERIAL_NUMBER ='IXJ147241'))
--AND A.WORK_ORDER ='100S-209104'))
UNION ALL
(SELECT A.WORK_ORDER
,A.PALLET_NO
,A.SERIAL_NUMBER
,B.PROCESS_NAME
,'10'AS STEP
,'Install component - S/N' AS ACTION
,C.BARCODE AS DEFECT_CODE
,null
,A.OUT_PROCESS_TIME
,null
,null
,null
,null
,null
FROM SAJET.G_SN_TRAVEL A,SAJET.SYS_PROCESS B , SAJET.G_BARCODE C,SAJET.SYS_PART D
WHERE A.PROCESS_ID = B.PROCESS_ID
AND A.SERIAL_NUMBER = C.SERIAL_NUMBER
AND A.MODEL_ID = D.PART_ID
AND B.PROCESS_NAME ='MAC MAP'
AND A.SERIAL_NUMBER ='IXJ147241')
--AND A.WORK_ORDER ='100S-209104')
非常感謝大家幫忙

thwu iT邦新手 4 級 ‧ 2019-03-27 09:24:31 檢舉
也許可以貼個預期結果的假資料,好有個參考。
另外也建議將 SQL 用 markdown 程式碼 tag 起來,至少可以好檢視一些。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答