表1
A      B      C      D
a1     b1     c1     1
a1     b1     c3     2
a1     b2     c1     3
a2     b4     c2     2
a2     b2     c3     5
a3     b5     c7     3
a3     b3     c1     1
希望结果是以A为索引,取D最小值的记录
结果
A      B      C      D
a1     b1     c1     1
a2     b4     c2     2
a3     b3     c1     1

解决方案 »

  1.   

    select * from table x,
    (select a as a ,min(d) as d from table
    group by a) y 
    where x.a=y.a and x.d=y.d
      

  2.   

    有没有比这个语句跟好点的
    select * from table x,
    (select a as a ,min(d) as d from table
    group by a) y  
    where x.a=y.a and x.d=y.d
      

  3.   

    SELECT * FROM TAB
    WHERE ROWNUM=1
    GROUP BY A,D
    ORDER BY A,D
      

  4.   

    select * from 
    (select t.*,row_number() over(partition by a order by d asc) rn from test t)
    where rn=1
      

  5.   

    SELECT * FROM TAB
    WHRE (A,D) IN
    (SELECT A,MIN(D) FROM TAB
    GROUP BY A)
    WHERE ROWNUM=1
      

  6.   


    select * from tb t where d in(select min(d) from tb where t.a=a group by a)