select * from table_name where rowid in 
(select rowid from (select a1,max(a2) from table_name group by a1))

解决方案 »

  1.   

    SELECT * 
    FROM
      TABLE_NAME T1,
      (SELECT ROWID,A1,MAX(A2) FROM TABLE_NAME GROUP BY ROWID,A1) T2
    WHERE T1.ROWID=T2.ROWID
      

  2.   

    这样也可以
    select * from table_name where (a1,a2) in
    (select a1,max(a2) from table_name group by a1);
      

  3.   

    jiezhi(西域浪子) :
         你写SQL文根本运行不了,提示分组查询结果集中没有rowid字段
    liuchangxing(小红星):
         你写的SQL文可以运行,但是查旬的数据比想要的结果多出了几条
      

  4.   

    select col1,max(col2) from table_name group by col1
      

  5.   

    可能是我的表达有些不清楚,我在具体解释一下:
    我就是想取得按a1分组,a2最大的那条数,如果a2最大的有多条的情况下,可以任取其中一条,但是a3,a4必须是那相对应的对录的数据,不能取到别的记录的数据比如:
         a1  a2 a3 a4
    1条   1,2,30,60
    2条   1, 2, 40,70
    3条   1, 1, 50,80
    要得到的结果可以是第一条,或者是第二条,但只能是 1,2,30,60 或者 1,2,40,70 但不能是
    1,2,40,60,或者是1,2,30,70和第三条。
      

  6.   

    参考一下
    select rowid,bdsszd from BADWDJ a where a.rowid = (select max(rowid) from BADWDJ b where a.bdsszd =b.bdsszd)
      

  7.   

    select * from table_name where rowid in 
    (select max(rowid) from table_name where (a1,a2) in (select a1,max(a2) from table_name group by a1) group by a1)
      

  8.   

    可以试一下:
      select * from table_name T where group by a1 having (count(a1)>1 and a2=select max(a2) from table_name )  and rowid=select max(rowid) from table_name group by a1 having count(a1)>1