表结构如下 TAB1:
id    name   type   xmbh   accepttime 
1001  测试1   01    xmbh01  2009-02-01
1002  测试1   02    xmbh01  2009-02-02
1003  测试1   03    xmbh01  2009-02-03
1004  测试1   04    xmbh01  2009-02-04
1005  测试2   01    xmbh02  2009-03-01
1006  测试3   02    xmbh03  2009-04-02
1007  测试2   03            2009-05-03
1008  测试2   04            2009-06-04
1009  测试6   01    xmbh06  2009-07-04
1010  测试6   02    xmbh06  2009-08-04
1011  测试66  03    xmbh666 2009-08-14
1012  测试6   04            2009-08-14
1013  测试7   01    xmbh07  2009-08-17
1014  测试7   02            2009-08-17
1015  测试7   03            2009-08-17
1016  测试7   04            2009-08-17
1017  测试8   01    xmbh08  2009-08-18
查询后的显示结果:
   name      xmbh     accepttime01   accepttime02   accepttime03     accepttime04
   测试1     xmbh01   2009-02-01      2009-02-02     2009-02-03       2009-02-04
   测试2     xmbh02   2009-03-01       无              ?                  ?
   测试6     xmbh06   2009-07-04      2009-08-04      无                  ?
   测试7     xmbh07   2009-08-17        ?              ?                  ?
   测试8     xmbh08   2009-08-18        无              无                  无
   
   说明:
  ?就是在其他类型中有与类型type=01中有相同的NAME但是没有项目编号。 
  “无”就是在其他类型中既没与类型type=01中有相同的NAME也没有相同的项目编号。
  “(2009-02-02)显示日期”只要 在其他类型中有与类型type=01中有相同的项目编号。

解决方案 »

  1.   

    不好意思,有点乱微调了一下
    表结构如下 TAB1: 
    id    name   type   xmbh      accepttime 
    1001  测试1   01     xmbh01    2009-02-01 
    1002  测试1   02     xmbh01    2009-02-02 
    1003  测试1   03     xmbh01    2009-02-03 
    1004  测试1   04     xmbh01    2009-02-04 
    1005  测试2   01     xmbh02    2009-03-01 
    1006  测试3   02     xmbh03    2009-04-02 
    1007  测试2   03               2009-05-03 
    1008  测试2   04               2009-06-04 
    1009  测试6   01     xmbh06    2009-07-04 
    1010  测试6   02     xmbh06    2009-08-04 
    1011  测试66  03     xmbh666   2009-08-14 
    1012  测试6   04               2009-08-14 
    1013  测试7   01     xmbh07    2009-08-17 
    1014  测试7   02               2009-08-17 
    1015  测试7   03               2009-08-17 
    1016  测试7   04               2009-08-17 
    1017  测试8   01     xmbh08    2009-08-18 
    查询后的显示结果: 
      name      xmbh     accepttime01    accepttime02   accepttime03    accepttime04 
      测试1     xmbh01   2009-02-01      2009-02-02     2009-02-03       2009-02-04 
      测试2     xmbh02   2009-03-01      无               ?                  ? 
      测试6     xmbh06   2009-07-04      2009-08-04     无                  ? 
      测试7     xmbh07   2009-08-17       ?               ?                 ? 
      测试8     xmbh08   2009-08-18      无               无                  无 
      
      说明: 
      ?就是在其他类型中有与类型type=01中有相同的NAME但是没有项目编号。 
      “无”就是在其他类型中既没与类型type=01中有相同的NAME也没有相同的项目编号。 
      “(2009-02-02)显示日期”只要 在其他类型中有与类型type=01中有相同的项目编号。 
      

  2.   

    SQL> select * from tmp_t2;ID         NAME       TYPE       XMBH       ACCEPTTIME
    ---------- ---------- ---------- ---------- --------------
    1001       测试1      01         xmbh01     01-2月 -09
    1002       测试1      01         xmbh01     02-2月 -09
    1003       测试1      01         xmbh01     04-2月 -09
    1004       测试1      01         xmbh01     22-2月 -09
    1005       测试2      02         xmbh02     04-2月 -09
    1006       测试2      02         xmbh02     05-2月 -09已选择6行。SQL> ed
    已写入 file afiedt.buf  1  select name,xmbh,accepttime1,accepttime2,accepttime3,accepttime4
      2  from(
      3   select name,xmbh,accepttime accepttime1,
      4   lead(accepttime,1,null) over(partition by xmbh order by id) accepttime2,
      5   lead(accepttime,2,null) over(partition by xmbh order by id) accepttime3,
      6   lead(accepttime,3,null) over(partition by xmbh order by id) accepttime4,
      7   rank() over(partition by xmbh order by rownum) rn
      8  from tmp_t2
      9  )
     10* where rn=1
    SQL> /NAME       XMBH       ACCEPTTIME1    ACCEPTTIME2    ACCEPTTIME3    ACCEPTTIME4
    ---------- ---------- -------------- -------------- -------------- --------------
    测试1      xmbh01     01-2月 -09     02-2月 -09     04-2月 -09     22-2月 -09
    测试2      xmbh02     04-2月 -09     05-2月 -09
      

  3.   

    就是行列转换,只是你的条件看不懂.大致是这样:select name , 
      max(xmbh) xmbh ,
      max(...) accepttime01,
      max(...) accepttime02,
      max(...) accepttime03,
      max(...) accepttime04
    from tb
    group by name
      

  4.   

    这个不难,用行列转换MAX+DECODE+GROUP就能实现
      

  5.   

    如果ACCEPTTIME 没有天数限制的话,那不是排列不完了.哈哈