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
where a.jzshbz=2
and a.xsbm=b.xsbm
and a.lsh=b.lsh
调试欢乐多
where jzshbz=2
本人建了个表测试过。下面的脚本测试过,你试一下:
SELECT DISTINCT xsbm AS xsbm,
(SELECT MAX(lsh)
FROM table2 b
WHERE a.xsbm = b.xsbm) AS MaxLsh, zcsl AS zcsl, jzshbz AS jzshbz
FROM TABLE2 a
WHERE (zcsl = 2)将TABLE2换成你的表名。