如表
 id       appid          date
  1        30         2007-03-11... 
  2        30         2007-03-12... 
  3        30         2007-03-13... 
  4        31         2007-03-24... 
  5        31         2007-03-12... 
  6        31         2007-03-13... 要得到的结果是:
  1        30         2007-03-11... 
  5        31         2007-03-12... 
就是以 appid 为组中的时间最小的行.

解决方案 »

  1.   

    select * from test123 where adate in (select min(adate) from test123 group by aappid)
      

  2.   

    create table  test123(aid int,aappid int, adate date)select * from test123 where adate in (select min(adate) from test123 group by aappid)
    /*
    id appid date
    1 30 2007-03-11...
    2 30 2007-03-12...
    3 30 2007-03-13...
    4 31 2007-03-24...
    5 31 2007-03-12...
    6 31 2007-03-13... 
    */
    输出结果
    1 1 30 2007-3-11
    2 4 31 2007-3-14
      

  3.   

    如果有adate相同,那就会多出一条记录,那怎么办呢?
      

  4.   

    select appid ,max(date) from table1 group by appid
      

  5.   

    select * from test123 where adate in (select min(adate) from test123 group by aappid,adate)
      

  6.   

    听我的,没错:
    select 
    first_value(id) over(partition by appid order by date) as id,
    first_value(appid) over(partition by appid order by date) as appid,
    first_value(date) over(partition by appid order by date) as date
    from 表
      

  7.   

    select * from test123 where (rowid,adate) in (select rowid, min(adate) from test123 group by aappid)
      

  8.   

    终于弄好了,谢谢大家!select distinct
    first_value(id) over(partition by appid order by date) as id,
    first_value(date) over(partition by appid order by date) as date,
    appid as appid
    from 表
      

  9.   

    哈哈。简单:)
    select * from test where (to_char(appid) || to_char(date_time,'yyyy mm dd')) in 
    ( select min(to_char(appid) || to_char(date_time,'yyyy mm dd')) from test group by appid);