0

我最近发现我们可以使用 Oracle 的 Max ( Decode ()) 函数来透视表的结果。我执行得很好。但是,旋转表格只是我需要的解决方案的一部分。旋转函数的结果如下:

01,02,03,05,06,07,08,09,10,11,12,13,14,16,17,20,21,23,25

我真正需要的是这样的:

1-17, 20-21,23,25

我真的不知道如何开始解决这个问题,但到目前为止我有以下查询:

SELECT DISTINCT
     MAX(DECODE(wldw.wafernumber,'01', '01')) 
      || MAX(DECODE(wldw.wafernumber,'02', ',02')) 
      || MAX(DECODE(wldw.wafernumber,'03', ',03')) 
      || MAX(DECODE(wldw.wafernumber,'04', ',04')) 
      || MAX(DECODE(wldw.wafernumber,'05', ',05')) 
      || MAX(DECODE(wldw.wafernumber,'06', ',06')) 
      || MAX(DECODE(wldw.wafernumber,'07', ',07')) 
      || MAX(DECODE(wldw.wafernumber,'08', ',08')) 
      || MAX(DECODE(wldw.wafernumber,'09', ',09')) 
      || MAX(DECODE(wldw.wafernumber,'10', ',10')) 
      || MAX(DECODE(wldw.wafernumber,'11', ',11')) 
      || MAX(DECODE(wldw.wafernumber,'12', ',12')) 
      || MAX(DECODE(wldw.wafernumber,'13', ',13')) 
      || MAX(DECODE(wldw.wafernumber,'14', ',14')) 
      || MAX(DECODE(wldw.wafernumber,'15', ',15')) 
      || MAX(DECODE(wldw.wafernumber,'16', ',16')) 
      || MAX(DECODE(wldw.wafernumber,'17', ',17')) 
      || MAX(DECODE(wldw.wafernumber,'18', ',18')) 
      || MAX(DECODE(wldw.wafernumber,'19', ',19')) 
      || MAX(DECODE(wldw.wafernumber,'20', ',20')) 
      || MAX(DECODE(wldw.wafernumber,'21', ',21')) 
      || MAX(DECODE(wldw.wafernumber,'22', ',22')) 
      || MAX(DECODE(wldw.wafernumber,'23', ',23')) 
      || MAX(DECODE(wldw.wafernumber,'24', ',24')) 
      || MAX(DECODE(wldw.wafernumber,'25', ',25'))  AS WAFERS      
      , 'history' as well
FROM a_wiplothistory wl
JOIN Container C ON (wl.containerid = c.containerid OR wl.containerid= c.splitfromid )
JOIN a_wiplotdetailshistory wld ON wl.wiplothistoryid = wld.wiplothistoryid
JOIN a_wiplotdetailswafershistory wldw ON wld.wiplotdetailshistoryid = wldw.wiplotdetailshistoryid
WHERE c.containername = :lot

感谢您的帮助。

4

1 回答 1

0
SELECT DISTINCT
 MAX(CASE WHEN wldw.wafernumber BETWEEN '01' AND '17' THEN '01-17' END)
  || MAX(DECODE(wldw.wafernumber,'18', ',18')) 
  || MAX(DECODE(wldw.wafernumber,'19', ',19')) 
  || MAX(CASE WHEN wldw.wafernumber IN ('20','21') THEN '20-21' END) 
  || MAX(DECODE(wldw.wafernumber,'21', ',21')) 
  || MAX(DECODE(wldw.wafernumber,'22', ',22')) 
  || MAX(DECODE(wldw.wafernumber,'23', ',23')) 
  || MAX(DECODE(wldw.wafernumber,'24', ',24')) 
  || MAX(DECODE(wldw.wafernumber,'25', ',25'))  AS WAFERS      
  , 'history' as well
于 2013-05-16T05:08:14.040 回答