日期:2014-05-18 浏览次数:20579 次
create table ca (ID int, A int, B int) insert into ca select 1, 10, 0 union all select 2, 10, 0 union all select 3, 10, 1 union all select 4, 10, 2 union all select 5, 11, 0 union all select 6, 12, 3 union all select 7, 12, 3 union all select 8, 13, 4 select t.ID, t.A, t.B from (select row_number() over(partition by A order by B) rn, * from ca) t where t.rn=1 ID A B ----------- ----------- ----------- 1 10 0 5 11 0 6 12 3 8 13 4
------解决方案--------------------
select * from tb t where id=(select min(id) from tb where a=t.a)
------解决方案--------------------