现有一张数据表  编号 最小时间     最大时间
01  2007-01-01  2007-02-01
02  2007-02-01  2007-03-01
03  2007-03-01  2007-05-01
我想得到这样的结果集  ,时间取极值、编号数据不变编号 最小时间     最大时间
01  2007-01-01  2007-05-01
02  2007-01-01  2007-05-01
03  2007-01-01  2007-05-01请问如何实现?

解决方案 »

  1.   

    select 编号,min(最小时间),max(最小时间) from table_name group by 编号
      

  2.   

    select t1.id ,t2.mintime,t2.maxtime from table t1 ,(select min(time) mintime ,max(time) maxtime from table) t2
      

  3.   


    select 编号,
           (select min(最小时间) from tb) 最小时间,
           (select max(最大时间) from tb) 最大时间
    from tb t
      

  4.   

    select 编号,min(最小时间 ) over(),max(最大时间) over() from 表名
      

  5.   

    create table tb(编号 varchar(2) , 最小时间 varchar(10) , 最大时间 varchar(10))
    insert into tb values('01' , '2007-01-01' , '2007-02-01')  
    insert into tb values('02' , '2007-02-01' , '2007-03-01')  
    insert into tb values('03' , '2007-03-01' , '2007-05-01')  
    goselect 编号, 
           (select min(最小时间) from tb) 最小时间, 
           (select max(最大时间) from tb) 最大时间 
    from tb tdrop table tb/*
    编号   最小时间       最大时间       
    ---- ---------- ---------- 
    01   2007-01-01 2007-05-01
    02   2007-01-01 2007-05-01
    03   2007-01-01 2007-05-01(所影响的行数为 3 行)*/
      

  6.   

    select 编号,mint,maxt 
    from table_name,(select min(最小时间) mint,max(最小时间) maxt from table_name) t
      

  7.   

    問一下樓上的hebo2005 
     over()在oracle 中有什麼作用,應該怎麼用? 謝謝!
      

  8.   

    select a.id,b.time1,b.time2
    from tabname a join 
    (
    SELECT MAX(time1) as time1,max(time2) as  time2 from tabname
    ) b  on 1=1这个方法你测试下,是否满足要求
      

  9.   

    Oracle数据库学习资源
    http://www.japee.com.cn/jew/pages/JPF2023_daoxian.aspx
      

  10.   

    2 楼仁兄的也是正确的。conn scott/*******create table tb(编号 number(2) , 最小时间 varchar2(10) , 最大时间 varchar2(10));
    insert into tb values('01' , '2007-01-01' , '2007-02-01') ; 
    insert into tb values('02' , '2007-02-01' , '2007-03-01');  
    insert into tb values('03' , '2007-03-01' , '2007-05-01');  
    select tb.编号 ,t2.mintime,t2.maxtime 
    from  tb ,(select min(最小时间) mintime ,max(最大时间) maxtime from  tb) t2;编号   mintime      maxtime      
    ---- ---------- ---------- 
    01   2007-01-01 2007-05-01
    02   2007-01-01 2007-05-01
    03   2007-01-01 2007-05-01