有表:
编号    书名    ISBN
1         a     4-1-1
2         a     4-1-1
3         a     4-1-1
4         a     4-1-1
5         b     4-3-2
6         b     4-3-2
7         b     4-3-2
8         b     4-3-2
9         c     4-5-2
10        d     4-7-2
11        d     4-7-2
12        d     4-7-2如何写SQL语句 获得以下表??(根据ISBN分组)
编号    书名    ISBN
1         a     4-1-1
5         b     4-3-2
9         c     4-5-2
10        d     4-7-2

解决方案 »

  1.   

    select * 
    from tb t
    where not exists(select 1 from tb where ISBN=t.ISBN and 编号<t.编号)
      

  2.   


    select * 
    from tb t
    where not exists(select 1 from tb where ISBN=t.ISBN and 编号<t.编号)
    select * 
    from tb t
    where 编号 = (select min(编号) from tb where ISBN=t.ISBN)
      

  3.   

    select b.* from
    (select distinct ISBN from tb) a
    cross apply
    (select top(1) * from tb where ISBN = a.ISBN order by 编号) bselect 编号=MIN(编号), 书名, ISBN FROM tb group by 书名, ISBN
      

  4.   

    select 编号=MIN(编号), 书名, ISBN FROM tb group by 书名, ISBN