问题如下:在一张表中有若干字段,有些记录只有‘时长’这个字段不同,其他都相同,请问我怎么样才能取出‘时长’最大的这类记录?比如我有‘姓名’,‘性别’,‘时长’这3个字段,表中存在姓名、性别相同,但时长不同的记录,需要提取时长为最大的记录出来。(PS:姓名有多个)烦请各位前辈指点!

解决方案 »

  1.   

    select ‘姓名’,‘性别’,max(‘时长’)
    from tablea
    group by ‘姓名’,‘性别’
      

  2.   

    select  distinct ‘姓名’,‘性别’,max(‘时长’) 
    from   tablea 
    group   by   ‘姓名’,‘性别’
      

  3.   

    select * form tablea where ‘姓名’,‘性别’,‘时长' in (select     ‘姓名’,‘性别’,max(‘时长’)  
    from       tablea  group       by       ‘姓名’,‘性别)
      

  4.   

    select a.*
      from table a,
           (select column a,
                   column b,
                   column c,
                   column d,
                   column e,
                   max(column f) sc
              from table
             group by column a,
                   column b,
                   column c,
                   column d,
                   column e) b
     where a.column a = b.column a
       and a.column b = b.column b
       and a.column c = b.column c
       and a.column d = b.column d
       and a.column e = b.column e
       and a.column f = b.sc;
    用这个语句就OK了,谢谢大家。