日期:2014-05-20 浏览次数:20868 次
List<int> list = new List<int>() {1,3,5,6,7,8,10 }; var query = Enumerable.Range(list.Min(), list.Max() - list.Min()+1).Except(list); query.ToList().ForEach(p => Console.WriteLine(p));
------解决方案--------------------
还真想不出好的方法
就是集合的减法,但实现基本和上边的一样
------解决方案--------------------
CREATE TABLE TB(col CHAR(5)) INSERT dbo.TB SELECT '00001' UNION ALL SELECT '00002' UNION ALL SELECT '00003' UNION ALL SELECT '00004' UNION ALL SELECT '00005' UNION ALL SELECT '00007' UNION ALL SELECT '00008' UNION ALL SELECT '00009' UNION ALL SELECT '00011' ; DECLARE @n AS INT SELECT @n=MAX(col) FROM dbo.TB ; WITH cte AS ( SELECT 1 AS n UNION ALL SELECT n+1 FROM cte WHERE n<@n ) SELECT RIGHT('0000' + CONVERT(VARCHAR(5), n), 5) FROM cte WHERE n NOT IN ( SELECT col FROM dbo.TB ) DROP TABLE dbo.TB /* --------- 00006 00010 (2 行受影响)*/