2013-03-14 106 views
0

你好再次非常慷慨的人。我想弄清楚如何獲得組內最新的記錄?圖像附加如下:只獲得組內最新記錄

enter image description here

基於該結果設定以上,有晶片號的兩次插入7和11我的問題是,在這樣的情況下,即在一定的晶片數量已經超過一個插入,我應該只顯示更近的插入是兩個。我如何在我的查詢中執行此操作?下面是該查詢我到目前爲止:

SELECT wipdata.wafernumber 
     ,wipdata.specname 
     ,wipdata.insertionnumber 
     ,wipdata.insertionreasonname 
     ,wipdata."Total Good DPW" 
     ,wipdata."Accept Bins B1" 
     ,wipdata."Accept Bins B2" 
     ,wipdata."Accept Bins B3" 
     ,wipdata."Accept Bins B4" 
     ,wipdata."Reject Continuity" 
     ,wipdata."Total Rejects" 
     ,wipdata."Probe Mark Insp" 
     ,wipdata."Ink Dot Insp" 
     ,wipdata."Visual Insp" 
     ,wipdata."Comments" 
     ,wipdata."Operator" 
     ,wipdata."Inspector" 
     ,wipdata."Engineer" 
     ,wipdata."Supervisor" 
     --,mh.wipdatavalue "MH" 
     ,wipdata."TPE Disposition" 
     ,wipdata."Supervisor Disposition" 
     ,wipdata."Check Code" 
     ,wipdata."Laser power Setup" 
     ,wipdata."Laser Trim Energy" 
     ,wipdata."Duan Ink" 
     ,wipdata."Inked Edges" 
     ,wipdata."100% Visual Qty" 
     ,wipdata."New Total GDPW" 
     ,wipdata."Yield" 
     ,wipdata.txndate 
     ,DECODE(SUBSTR(wipdata.specname,0,4),'5267','12345', wipdata.equipmentid) equipmentid 
FROM 
(
SELECT c.containername 
     ,wl.specid 
     ,wl.specname 
     ,wl.wiptrackinggroupkeyid 
     ,wl.wiplothistoryid 
     ,wld.wiplotdetailshistoryid 
     ,wldd.wiplotdetailsdatahistoryid 
     ,wldw.wafernumber 
     ,wldd.wipdatanamename 
     ,TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0)) AS "Total Good DPW" 
     ,ab1.wipdatavalue "Accept Bins B1" 
     ,ab2.wipdatavalue "Accept Bins B2" 
     ,ab3.wipdatavalue "Accept Bins B3" 
     ,ab4.wipdatavalue "Accept Bins B4" 
     ,rc.wipdatavalue "Reject Continuity" 
     ,wldw.processwaferrejectsqty "Total Rejects" 
     ,pmi.wipdatavalue "Probe Mark Insp" 
     ,idi.wipdatavalue "Ink Dot Insp" 
     ,vip.wipdatavalue "Visual Insp" 
     ,comments.wipdatavalue "Comments" 
     ,oper.wipdatavalue "Operator" 
     ,insp.wipdatavalue "Inspector" 
     ,engr.wipdatavalue "Engineer" 
     ,supv.wipdatavalue "Supervisor" 
     --,mh.wipdatavalue "MH" 
     ,tpeDispo.wipdatavalue "TPE Disposition" 
     ,supvDispo.wipdatavalue "Supervisor Disposition" 
     ,cc.Wipdatavalue "Check Code" 
     ,lps.Wipdatavalue "Laser power Setup" 
     ,lte.Wipdatavalue "Laser Trim Energy" 
     ,di.Wipdatavalue "Duan Ink" 
     ,ie.Wipdatavalue "Inked Edges" 
     ,vq.Wipdatavalue "100% Visual Qty" 
     ,ntg.Wipdatavalue "New Total GDPW" 
     , CASE WHEN (TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0))) = 0 THEN NULL 
      ELSE ROUND((TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0))) 
     /(TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0)) + 
     wldw.processwaferrejectsqty - TO_NUMBER(NVL(rc.wipdatavalue,0))) * 100, 2) END AS "Yield" 
     ,wldd.txntimestamp txndate 
     ,wldw.wafersequence 
     ,wldw.equipmentid 
     ,wl.insertionnumber 
     ,wl.insertionreasonname 
FROM a_wiplothistory wl 
JOIN Container C ON wl.containerid = c.containerid 
JOIN a_wiplotdetailshistory wld ON wl.wiplothistoryid = wld.wiplothistoryid 
JOIN a_wiplotdetailsdatahistory wldd ON wld.wiplotdetailshistoryid = wldd.wiplotdetailshistoryid 
LEFT JOIN a_wiplotdetailswafershistory wldw ON wldw.wiplotdetailshistoryid = wld.wiplotdetailshistoryid AND wldd.waferscribenumber = wldw.waferscribenumber 
LEFT JOIN a_wiplotdetailsdatahistory ab1 ON wld.wiplotdetailshistoryid = ab1.wiplotdetailshistoryid AND ab1.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab1.wipdatanamename)) = 'WS_ACCEPT BIN1' 
LEFT JOIN a_wiplotdetailsdatahistory ab2 ON wld.wiplotdetailshistoryid = ab2.wiplotdetailshistoryid AND ab2.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab2.wipdatanamename)) = 'WS_ACCEPT BIN2' 
LEFT JOIN a_wiplotdetailsdatahistory ab3 ON wld.wiplotdetailshistoryid = ab3.wiplotdetailshistoryid AND ab3.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab3.wipdatanamename)) LIKE 'WS_%ACCEPT BIN3' 
LEFT JOIN a_wiplotdetailsdatahistory ab4 ON wld.wiplotdetailshistoryid = ab4.wiplotdetailshistoryid AND ab4.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab4.wipdatanamename)) LIKE 'WS_%ACCEPT BIN4' 
LEFT JOIN a_wiplotdetailsdatahistory tr ON wld.wiplotdetailshistoryid = tr.wiplotdetailshistoryid AND tr.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(tr.wipdatanamename)) = 'WS_TOTAL REJECTS' 
LEFT JOIN a_wiplotdetailsdatahistory rc ON wld.wiplotdetailshistoryid = rc.wiplotdetailshistoryid AND rc.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(rc.wipdatanamename)) = 'WS_REJECT CONTINUITY' 
LEFT JOIN a_wiplotdetailsdatahistory pmi ON wld.wiplotdetailshistoryid = pmi.wiplotdetailshistoryid AND pmi.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(pmi.wipdatanamename)) LIKE 'WS_PM/LASER%' 
LEFT JOIN a_wiplotdetailsdatahistory idi ON wld.wiplotdetailshistoryid = idi.wiplotdetailshistoryid AND idi.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(idi.wipdatanamename)) LIKE 'WS_INK%DOT%' 
LEFT JOIN a_wiplotdetailsdatahistory vip ON wld.wiplotdetailshistoryid = vip.wiplotdetailshistoryid AND vip.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(vip.wipdatanamename)) LIKE 'WS_VISUAL%' 
LEFT JOIN a_wiplotdetailsdatahistory comments ON wld.wiplotdetailshistoryid = comments.wiplotdetailshistoryid AND comments.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(comments.wipdatanamename)) = 'WS_COMMENTS' 
LEFT JOIN a_wiplotdetailsdatahistory oper ON wld.wiplotdetailshistoryid = oper.wiplotdetailshistoryid AND oper.waferscribenumber = wldd.waferscribenumber AND (TRIM(UPPER(oper.wipdatanamename)) = 'WS_OPERATOR' OR TRIM(UPPER(oper.wipdatanamename)) = 'WS_OPERATOR_GRID') 
LEFT JOIN a_wiplotdetailsdatahistory insp ON wld.wiplotdetailshistoryid = insp.wiplotdetailshistoryid AND insp.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(insp.wipdatanamename)) = 'WS_INSPECTOR' 
LEFT JOIN a_wiplotdetailsdatahistory engr ON wld.wiplotdetailshistoryid = engr.wiplotdetailshistoryid AND engr.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(engr.wipdatanamename)) LIKE 'WS_%ENGINEER' 
LEFT JOIN a_wiplotdetailsdatahistory supv ON wld.wiplotdetailshistoryid = supv.wiplotdetailshistoryid AND supv.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(supv.wipdatanamename)) = 'WS_SUPERVISOR' 
LEFT JOIN a_wiplotdetailsdatahistory tpeDispo ON wld.wiplotdetailshistoryid = tpeDispo.wiplotdetailshistoryid AND tpeDispo.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(tpeDispo.wipdatanamename)) = 'WS_TPE DISPOSITION' 
LEFT JOIN a_wiplotdetailsdatahistory supvDispo ON wld.wiplotdetailshistoryid = supvDispo.wiplotdetailshistoryid AND supvDispo.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(supvDispo.wipdatanamename)) = 'WS_SUPV DISPOSITION' 
--LEFT JOIN a_wiplotdetailsdatahistory mh ON wld.wiplotdetailshistoryid = mh.wiplotdetailshistoryid AND mh.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(mh.wipdatanamename)) = 'WS_MH' 
LEFT JOIN a_wiplotdetailsdatahistory cc ON wld.wiplotdetailshistoryid = cc.wiplotdetailshistoryid AND cc.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(cc.wipdatanamename)) = 'WS_CHECK CODE' 
LEFT JOIN a_wiplotdetailsdatahistory lps ON wld.wiplotdetailshistoryid = lps.wiplotdetailshistoryid AND lps.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(lps.wipdatanamename)) = 'WS_LASER POWER SETUP(P/F)' 
LEFT JOIN a_wiplotdetailsdatahistory lte ON wld.wiplotdetailshistoryid = lte.wiplotdetailshistoryid AND lte.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(lte.wipdatanamename)) LIKE 'WS_LASER TRIM ENERGY%' 
LEFT JOIN a_wiplotdetailsdatahistory di ON wld.wiplotdetailshistoryid = di.wiplotdetailshistoryid AND di.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(di.wipdatanamename)) = 'WS_DUAL INK (Y/N)' 
LEFT JOIN a_wiplotdetailsdatahistory ie ON wld.wiplotdetailshistoryid = ie.wiplotdetailshistoryid AND ie.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ie.wipdatanamename)) = 'WS_INKED EDGES (Y/N)' 
LEFT JOIN a_wiplotdetailsdatahistory vq ON wld.wiplotdetailshistoryid = vq.wiplotdetailshistoryid AND vq.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(vq.wipdatanamename)) LIKE 'WS_100%VISUAL%QTY' 
LEFT JOIN a_wiplotdetailsdatahistory ntg ON wld.wiplotdetailshistoryid = ntg.wiplotdetailshistoryid AND ntg.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ntg.wipdatanamename)) = 'WS_NEW TOTAL GDPW' 

WHERE c.containername =:lotID AND (TRIM(UPPER(wldd.wipdatanamename)) = 'WS_ACCEPT BIN1' OR ((TRIM(UPPER(wldd.wipdatanamename)) LIKE 'WS_LASER TRIM ENERGY%' AND wl.specname LIKE '5207_%') 
                           OR (TRIM(UPPER(wldd.wipdatanamename)) LIKE 'WS_100%VISUAL%QTY' AND SUBSTR(wl.specname,0,4) = '5267') )) 

UNION ALL 

SELECT c.containername 
     ,wl.specid 
     ,wl.specname 
     ,wl.wiptrackinggroupkeyid 
     ,wl.wiplotid 
     ,wld.wiplotdetailsid 
     ,wldd.wiplotdetailsdataid 
     ,wldw.wafernumber 
     ,wldd.wipdatanamename 
     ,TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0)) AS "Total Good DPW" 
     ,ab1.wipdatavalue "Accept Bins B1" 
     ,ab2.wipdatavalue "Accept Bins B2" 
     ,ab3.wipdatavalue "Accept Bins B3" 
     ,ab4.wipdatavalue "Accept Bins B4" 
     ,rc.wipdatavalue "Reject Continuity" 
     ,wldw.processwaferrejectsqty "Total Rejects" 
     ,pmi.wipdatavalue "Probe Mark Insp" 
     ,idi.wipdatavalue "Ink Dot Insp" 
     ,vip.wipdatavalue "Visual Insp" 
     ,comments.wipdatavalue "Comments" 
     ,oper.wipdatavalue "Operator" 
     ,insp.wipdatavalue "Inspector" 
     ,engr.wipdatavalue "Engineer" 
     ,supv.wipdatavalue "Supervisor" 
     --,mh.wipdatavalue "MH" 
     ,tpeDispo.wipdatavalue "TPE Disposition" 
     ,supvDispo.wipdatavalue "Supervisor Disposition" 
     ,cc.Wipdatavalue "Check Code" 
     ,lps.Wipdatavalue "Laser power Setup" 
     ,lte.Wipdatavalue "Laser Trim Energy" 
     ,di.Wipdatavalue "Duan Ink" 
     ,ie.Wipdatavalue "Inked Edges" 
     ,vq.Wipdatavalue "100% Visual Qty" 
     ,ntg.Wipdatavalue "New Total GDPW" 
     , CASE WHEN (TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0))) = 0 THEN NULL 
      ELSE ROUND((TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0))) 
     /(TO_NUMBER(NVL(ab1.wipdatavalue,0)) + TO_NUMBER(NVL(ab2.wipdatavalue,0)) + TO_NUMBER(NVL(ab3.wipdatavalue,0)) + TO_NUMBER(NVL(ab4.wipdatavalue,0)) + 
     TO_NUMBER(NVL(wldw.processwaferrejectsqty,0)) - TO_NUMBER(NVL(rc.wipdatavalue,0))) * 100, 2) END AS "Yield" 
     ,wldd.txntimestamp txndate 
     ,wldw.wafersequence 
     ,wldw.equipmentid 
      ,wl.insertionnumber 
     ,wl.insertionreasonname 
FROM a_wiplot wl 
JOIN Container C ON wl.containerid = c.containerid 
JOIN a_wiplotdetails wld ON wl.wiplotid = wld.wiplotid 
JOIN a_wiplotdetailsdata wldd ON wld.wiplotdetailsid = wldd.wiplotdetailsid 
LEFT JOIN a_wiplotdetailswafers wldw ON wldw.wiplotdetailsid = wld.wiplotdetailsid AND wldd.waferscribenumber = wldw.waferscribenumber 
LEFT JOIN a_wiplotdetailsdata ab1 ON wld.wiplotdetailsid = ab1.wiplotdetailsid AND ab1.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab1.wipdatanamename)) = 'WS_ACCEPT BIN1' 
LEFT JOIN a_wiplotdetailsdata ab2 ON wld.wiplotdetailsid = ab2.wiplotdetailsid AND ab2.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab2.wipdatanamename)) = 'WS_ACCEPT BIN2' 
LEFT JOIN a_wiplotdetailsdata ab3 ON wld.wiplotdetailsid = ab3.wiplotdetailsid AND ab3.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab3.wipdatanamename)) LIKE 'WS_%ACCEPT BIN3' 
LEFT JOIN a_wiplotdetailsdata ab4 ON wld.wiplotdetailsid = ab4.wiplotdetailsid AND ab4.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ab4.wipdatanamename)) LIKE 'WS_%ACCEPT BIN4' 
LEFT JOIN a_wiplotdetailsdata tr ON wld.wiplotdetailsid = tr.wiplotdetailsid AND tr.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(tr.wipdatanamename)) = 'WS_TOTAL REJECTS' 
LEFT JOIN a_wiplotdetailsdata rc ON wld.wiplotdetailsid = rc.wiplotdetailsid AND rc.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(rc.wipdatanamename)) = 'WS_REJECT CONTINUITY' 
LEFT JOIN a_wiplotdetailsdata pmi ON wld.wiplotdetailsid = pmi.wiplotdetailsid AND pmi.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(pmi.wipdatanamename)) LIKE 'WS_PM/LASER%' 
LEFT JOIN a_wiplotdetailsdata idi ON wld.wiplotdetailsid = idi.wiplotdetailsid AND idi.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(idi.wipdatanamename)) LIKE 'WS_INK%DOT%' 
LEFT JOIN a_wiplotdetailsdata vip ON wld.wiplotdetailsid = vip.wiplotdetailsid AND vip.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(vip.wipdatanamename)) LIKE 'WS_VISUAL%' 
LEFT JOIN a_wiplotdetailsdata comments ON wld.wiplotdetailsid = comments.wiplotdetailsid AND comments.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(comments.wipdatanamename)) = 'WS_COMMENTS' 
LEFT JOIN a_wiplotdetailsdata oper ON wld.wiplotdetailsid = oper.wiplotdetailsid AND oper.waferscribenumber = wldd.waferscribenumber AND (TRIM(UPPER(oper.wipdatanamename)) = 'WS_OPERATOR' OR TRIM(UPPER(oper.wipdatanamename)) = 'WS_OPERATOR_GRID') 
LEFT JOIN a_wiplotdetailsdata insp ON wld.wiplotdetailsid = insp.wiplotdetailsid AND insp.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(insp.wipdatanamename)) = 'WS_INSPECTOR' 
LEFT JOIN a_wiplotdetailsdata engr ON wld.wiplotdetailsid = engr.wiplotdetailsid AND engr.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(engr.wipdatanamename)) LIKE 'WS_%ENGINEER' 
LEFT JOIN a_wiplotdetailsdata supv ON wld.wiplotdetailsid = supv.wiplotdetailsid AND supv.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(supv.wipdatanamename)) = 'WS_SUPERVISOR' 
LEFT JOIN a_wiplotdetailsdata tpeDispo ON wld.wiplotdetailsid = tpeDispo.wiplotdetailsid AND tpeDispo.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(tpeDispo.wipdatanamename)) = 'WS_TPE DISPOSITION' 
LEFT JOIN a_wiplotdetailsdata supvDispo ON wld.wiplotdetailsid = supvDispo.wiplotdetailsid AND supvDispo.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(supvDispo.wipdatanamename)) = 'WS_SUPV DISPOSITION' 
--LEFT JOIN a_wiplotdetailsdata mh ON wld.wiplotdetailsid = mh.wiplotdetailsid AND mh.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(mh.wipdatanamename)) = 'WS_MH' 
LEFT JOIN a_wiplotdetailsdata cc ON wld.wiplotdetailsid = cc.wiplotdetailsid AND cc.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(cc.wipdatanamename)) = 'WS_CHECK CODE' 
LEFT JOIN a_wiplotdetailsdata lps ON wld.wiplotdetailsid = lps.wiplotdetailsid AND lps.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(lps.wipdatanamename)) = 'WS_LASER POWER SETUP(P/F)' 
LEFT JOIN a_wiplotdetailsdata lte ON wld.wiplotdetailsid = lte.wiplotdetailsid AND lte.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(lte.wipdatanamename)) LIKE 'WS_LASER TRIM ENERGY%' 
LEFT JOIN a_wiplotdetailsdata di ON wld.wiplotdetailsid = di.wiplotdetailsid AND di.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(di.wipdatanamename)) = 'WS_DUAL INK (Y/N)' 
LEFT JOIN a_wiplotdetailsdata ie ON wld.wiplotdetailsid = ie.wiplotdetailsid AND ie.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ie.wipdatanamename)) = 'WS_INKED EDGES (Y/N)' 
LEFT JOIN a_wiplotdetailsdata vq ON wld.wiplotdetailsid = vq.wiplotdetailsid AND vq.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(vq.wipdatanamename)) LIKE 'WS_100%VISUAL%QTY' 
LEFT JOIN a_wiplotdetailsdata ntg ON wld.wiplotdetailsid = ntg.wiplotdetailsid AND ntg.waferscribenumber = wldd.waferscribenumber AND TRIM(UPPER(ntg.wipdatanamename)) = 'WS_NEW TOTAL GDPW' 

WHERE c.containername =:lotID AND (TRIM(UPPER(wldd.wipdatanamename)) = 'WS_ACCEPT BIN1' OR ((TRIM(UPPER(wldd.wipdatanamename)) LIKE 'WS_LASER TRIM ENERGY%' AND wl.specname LIKE '5207_%') 
                           OR (TRIM(UPPER(wldd.wipdatanamename)) LIKE 'WS_100%VISUAL%QTY' AND SUBSTR(wl.specname,0,4) = '5267') )) 
) wipdata 
WHERE wipdata."Total Good DPW" <> 0 AND wipdata."Total Rejects" <> 0 
ORDER BY wipdata.wafersequence; 

我知道你們會幫助多謝:)

回答

0

使用分析功能。這是一般形式:

SELECT wipdata.wafernumber 
    ,wipdata.specname 
    ,MAX(wipdata.insertionnumber) insertionnumber 
    ,MAX(wipdata.insertionreasonname) KEEP (DENSE_RANK LAST ORDER BY wipdata.insertionnumber) insertionreasonname 
    ,MAX(wipdata."Total Good DPW") KEEP (DENSE_RANK LAST ORDER BY wipdata.insertionnumber) "Total Good DPW" 
    ,MAX(wipdata."Accept Bins B1") KEEP (DENSE_RANK LAST ORDER BY wipdata.insertionnumber) "Accept Bins B1" 
    ,MAX(wipdata."Accept Bins B2") KEEP (DENSE_RANK LAST ORDER BY wipdata.insertionnumber) "Accept Bins B2" 
    ...... 
FROM 
(
...... 
) wipdata 
WHERE wipdata."Total Good DPW" <> 0 AND wipdata."Total Rejects" <> 0 
GROUP BY 
wipdata.wafernumber,wipdata.specname 
ORDER BY wipdata.wafersequence; 

希望你能看到你如何應用這個要點。這不太好,但它是最有效的方法之一。我建議你先試驗一個字段的子集,並逐個添加額外的字段,以避免出現語法錯誤。如果您需要語法錯誤幫助,請將完整查詢返回。

+0

你好ElectricLlama,我試過你的答案,但據說它不是GROUP BY表達式。 – GianIsTheName 2013-03-14 06:57:50

+0

嗨ElectricLlama,我更新了我用過的查詢。我在Total Good DPW上遇到問題。插入1仍然顯示。 – GianIsTheName 2013-03-14 07:35:30

+0

總是發佈所有信息 - 它節省每個人的時間 – 2013-03-14 07:38:59

0

嘗試:

select waffernumber, specname, insertionnumber 
from 
(
select waffernumber, specname, insertionnumber, rank() over (partition by waffernumber order by insertionnumber desc) rn 
from t 
) 
where rn = 1 

其中T是您查詢(我簡化它的例子)

Here is a sqlfiddle demo

+0

嗨凱德,我已經更新了我用過的查詢。我在Total Good DPW上遇到問題。插入1仍然顯示。 – GianIsTheName 2013-03-14 07:35:05

0

通過訂單前補充一點:

and wipdata.insertionnumber = (select max (x.insertionnumber) from (make a query that just  retrun "insertionnumber" and "wafernumber") x where x.wafernumber=wipdata.wafernumber) 

我希望它有效。