表字段和数据如下:
a  b  c
1  2 1
1  3 2
2  4 3
2  5 4
想问用什么sql语句实现显示数据如下:
a  b  c
1  2 1
2  4 3不会用group by a,b,c 吧?

解决方案 »

  1.   


    drop table aa
    create table aa(a int,b int,c int)
    insert into aa
    select 1, 2 ,1
    union all select 
    1 ,3 ,2
    union all select 
    2 ,4, 3
    union all select 
    2 ,5, 4 select * from aaselect a,b,c from
    ( select row_number() over(partition by a order by a) fr,* 
    from aa )a
    where fr=1
    /*
    1 2 1
    2 4 3
    */
      

  2.   

    select * from tb a where not exists(select 1 from tb where a=a.a and b<a.b)
      

  3.   

    select * from tb t where b=(select min(b) from tb where a=a.a)