一张表中有多个字段,A为编号,B为日期,C为name,现在要以A分组,取B的最大值,并且同时取出A,B这条记录的C,即查出的字段有A,B,C
谢谢了

解决方案 »

  1.   

    select * from tb t where t.a in (select a from (select a,max(b) group by a) t1)
    有主键用主键
      

  2.   

    select a,max(b) as 这个字段的名字,c from table group by a
      

  3.   

    select a,b,c from table groub by a where b=max(b)
    不晓的对不。自已跑下看
      

  4.   

    select t1.a,t1.b,t1.c from table t1,(select a,max(b) as b1 from table group by a) t2
    where t1.a = t2.a and t1.b = t2.b1
      

  5.   

    select * from (select t.* , row_number() over (partition by t.A order by t.B desc) rn from your_table t ) where rn<=1;
    语句经过测试,没问题,lz可以试一试
      

  6.   

    to kokobox:
    我在mysql下测了,报row_number()不能识别,不知道你在什么数据库下测的,谢谢to new_bird:
    你的是对的,3Q其他人有的语法错误,有的结果不符合要求,同样感谢结贴!