select * from 表 where rev=(select max(rev) from 表)

解决方案 »

  1.   

    select * from a where rev=(select max(rev) from a)
      

  2.   

    select * from 表 where rev= (select max(rev) from 表)
      

  3.   

    谢谢各位,这样不行的啊,如果记录为这样的话:
    Id      Name      Rev
    --------------------------
    1       aaa       1
    1       bbb       2
    1       ccc       3
    2       eee       1
    2       ffff      2
    2       gggk      3
    2       gggi      4就只能查出一条记录,而查不出2条的??
    请继续help
      

  4.   

    你这样的记录里面rev最大为4的,而且只有1条啊,所以当然只能查出1条记录啦
      

  5.   

    不好意思,还有一点最重要的没说明:按ID及NAME分组,即我要得到的记录为:
    Id      Name      Rev
    --------------------------
    1       ccc       32       gggi      4
      

  6.   

    select * from 表 where id||rev in(select distinct id||max(rev) from 表 group by id);  查出的只有 1   ccc  3  和  2     gggi     4,
    是不是你所要求的。
      

  7.   

    你是按ID分组吧,要是ID,NAME分组的话因为name不同,如:select * from 表 where rev in(select max(rev) from 表 group by id,name);所有记录都是满足条件的
      

  8.   

    --分组与查询记录最大的慨念是不同的.--如果是分组:
    select id,name,max(rev) from 表 group by id,name
    --如果是查询记录最大的:
    select * from 表 a where rev=(select max(rev) from 表 where id=a.id and name=b.name)
      

  9.   

    两者的差别就在于,如果只是楼主给出的数据,两种方法都合适.如果表中还有其中字段,要查询出每组rev值最大的记录,就只能用第二种方法.
      

  10.   

    select * from 表 tem where rev=(select max(rev) from 表 where id=tem.id)
      

  11.   

    SQL里面好像没"||"的,我把它改成“|”就错了
      

  12.   

    ||就是程序里面用的或运算符号,我知道在informix和postgresql中都是可以用的,我刚才是在postgresql中测试过的
      

  13.   

    select * from 表 where id+rev in(select distinct id+max(rev) from 表 group by id);
      

  14.   

    谢谢 pengdali(大力 V3.0)等各位其实我这个表只是一个结果集,但又没用存储过程,只在vb.net里面用,终于可以解决了!!!!!真的非常感谢!!!