0

嗨,请帮我解决我的疑问,我在 oracle9i 中得到这样的输出,

S.No   Column1     Column2  Column3  DateCol

1      A            B        C        10/2001 

2      A            B        C        03/2001  

3      B            B        C        02/2001 

4      B            B        C        01/2001

5      A            B        C        03/2000   

但我的真实情况是,我需要在下面的结构中填充输出

S.No   Column1     Column2  Column3  DateCol

1      A            B        C        10/2001 

       A            B        C        03/2001  

2      B            B        C        02/2001 

       B            B        C        01/2001

3      A            B        C        03/2000    

我不知道如何形成查询,检索结构,请帮帮我,我的学术项目已经过时了,请任何人为我提供解决方案..提前谢谢

4

1 回答 1

0
CREATE TABLE SCOTT.GROUP_SHOW_ONCE
(
  SR_NO    NUMBER,
  COL1     VARCHAR2(20 BYTE),
  COL2     VARCHAR2(20 BYTE),
  COL3     VARCHAR2(20 BYTE),
  DATECOL  DATE
)

Insert into GROUP_SHOW_ONCE
   (SR_NO, COL1, COL2, COL3, DATECOL)
 Values
   (1, 'A', 'B', 'C', TO_DATE('10/11/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into GROUP_SHOW_ONCE
   (SR_NO, COL1, COL2, COL3, DATECOL)
 Values
   (2, 'A', 'B', 'C', TO_DATE('03/11/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into GROUP_SHOW_ONCE
   (SR_NO, COL1, COL2, COL3, DATECOL)
 Values
   (3, 'B', 'B', 'C', TO_DATE('02/11/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into GROUP_SHOW_ONCE
   (SR_NO, COL1, COL2, COL3, DATECOL)
 Values
   (4, 'B', 'B', 'C', TO_DATE('01/11/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into GROUP_SHOW_ONCE
   (SR_NO, COL1, COL2, COL3, DATECOL)
 Values
   (5, 'A', 'B', 'C', TO_DATE('03/11/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;

---您的查询会喜欢

SELECT DECODE (rnn, LAG (rnn) OVER (ORDER BY TO_NUMBER (rnn)), NULL, rnn) sr_no,col1, col2, col3,datecol
  FROM (SELECT   col1, col2, col3,DATECOL,
                 ROW_NUMBER () OVER (PARTITION BY rn ORDER BY rn) rnn
            FROM (SELECT sr_no, col1, col2, col3,DATECOL,
                         ROW_NUMBER () OVER (PARTITION BY col1, col2, col3 ORDER BY sr_no)  rn
                    FROM group_show_once)
        ORDER BY rnn)
于 2012-06-04T04:50:49.360 回答