select max(bh),max(sz) from table1 group by bh

解决方案 »

  1.   

    select * from table1 group by bh having sz=max(sz)
      

  2.   

    select bh,max(sz) from table1 group by bh order by bh
      

  3.   

    請問用group by 時 哪些函數可放在select 中 而group by 後不再需要該字段進行分組
      

  4.   

    create table tb(bh varchar(10),sz int)
    Insert into tb 
    select 'M001',1
    union all select 'M001',3
    union all select 'M001',2
    union all select 'M002',1
    union all select 'M002',2
    union all select 'M002',3
    union all select 'M003',1
    union all select 'M004',1
    union all select 'M004',2
    union all select 'M004',2select * from tbselect bh,sz=max(sz) from tb group by bh--結果
    bh         sz
    -----------------
    M001 3
    M002 3
    M003 1
    M004 2看來只有這種方法最好了