日期:2014-05-17 浏览次数:20722 次
WITH tab (id, cpbh ,XH ,sjrq ) AS (SELECT 1, '001', 'A-1' ,'2011-02-09' UNION ALL SELECT 2 ,'001', 'A-2', '2012-03-07' UNION ALL SELECT 3 ,'001','A-3', '2012-06-20' UNION ALL SELECT 4 ,'002', 'B-1', '2012-04-15' UNION ALL SELECT 5 ,'002', 'B-2', '2012-06-01') SELECT * FROM TAB a WHERE EXISTS (SELECT 1 FROM (SELECT MAX(sjrq) sjrq ,cpbh FROM TAB GROUP BY cpbh)b WHERE a.sjrq=b.sjrq AND a.cpbh=b.cpbh) /* id cpbh XH sjrq ----------- ---- ---- ---------- 3 001 A-3 2012-06-20 5 002 B-2 2012-06-01 (2 行受影响) */