日期:2014-05-17  浏览次数:20818 次

新手求一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 TAB
WHRE (A,D) IN
(SELECT A,MIN(D) FROM TAB
GROUP 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)