select a.xsbm,a.zcsl from tablename as a,(select xsbm,max(lsh) as lsh from tablename where jzshbz=2 group by xsbm) as b
where a.jzshbz=2
and a.xsbm=b.xsbm
and a.lsh=b.lsh

解决方案 »

  1.   

    8992026(8992026)的写法性能上应该不错的了,你可以和下一句比较一下,应该差不多的.select a.xsbm,a.zcsl from tablename as a
    where a.jzshbz=2
    and lsh=(select max(lsh) as lsh from tablename b where jzshbz=2 and a.xsbm=b.xsbm
    )
      

  2.   

    感谢所有帮忙的人,尤其感谢: Yang_(扬帆破浪) and 8992026(8992026)
      

  3.   

    SELECT DISTINCT xsbm,
              (SELECT MAX(lsh)
             FROM TableName A
             WHERE A.zcsl = 2 AND A.xsbm = B.xsbm) AS lsh, zcsl, jzshbz
    FROM TableName B
    WHERE (zcsl = 2)