要求如下:
前提:一个表就叫user吧,里面有两个字段username,autoid.其中一个字段username是有重复的,另一个autoid是没有重复的.
现在我知道多个重复字段username的名称 如:a,b,c.如何一次一一对应的把这些知道的重复的字段username对应的另一个字段autoid中的最大的值取出来
表数据结构如下:username autoid
a        1
a        2
b        3
b        23
c        10
c        13
c        100我需要根据我知道的条件username=a,b,c来查询出来的结果应该是username autoid
a         2
b         23
c         100麻烦各位高手把sql写出来..想了半天了也想不出来怎么写.麻烦了.在线===

解决方案 »

  1.   

    select username,max(autoid) from table where username in(a,b,c) group by username
      

  2.   

    select max(autoid) from table where username in(select distinct username from table) group by username
      

  3.   

    select a.* from tt a where not exists(select 1 from tt where a.username=username and a.autoid<id)
      

  4.   

    or
    select username,max(autoid) from tt group by username
      

  5.   

    我用的wdz567
    同样感谢楼上的其他的回复者..今天貌似结不了帖子.明天来结贴送分.3q