当前位置: 代码迷 >> Oracle开发 >> 新手求一SQL
  详细解决方案

新手求一SQL

热度:239   发布时间:2016-04-24 08:03:38.0
新手求一SQL,在线等
表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


------解决方案--------------------
select * from 
(select t.*,row_number() over(partition by a order by d asc) rn from test t)
where rn=1
------解决方案--------------------
SQL code
SELECT * FROM TABWHRE (A,D) IN(SELECT A,MIN(D) FROM TABGROUP BY A)WHERE ROWNUM=1
------解决方案--------------------
SQL code
select * from tb t where d in(select min(d) from tb where t.a=a group by a)
  相关解决方案