日期:2014-05-17 浏览次数:20510 次
DECLARE @a TABLE(ID int,NAME VARCHAR(20))
INSERT @a SELECT 1 ,'ABC'
UNION ALL SELECT 2 ,'ABC'
UNION ALL SELECT 3 ,'ABC'
UNION ALL SELECT 4 ,'BBB'
SELECT a.*,b.* FROM @a a,@a b WHERE a.id>(SELECT MIN(id) FROM @a WHERE NAME=a.name)
AND b.id=(SELECT MIN(id) FROM @a WHERE NAME=a.name)
--result
/*ID NAME ID NAME
----------- -------------------- ----------- --------------------
2 ABC 1 ABC
3 ABC 1 ABC
(所影响的行数为 2 行)
*/