日期:2014-05-18 浏览次数:20652 次
-->生成测试数据:
GO
IF OBJECT_ID('TBL')IS NOT NULL
DROP TABLE TBL
GO
CREATE TABLE TBL(
ID INT
)
GO
INSERT TBL
SELECT 1 UNION ALL
SELECT 3 UNION ALL
SELECT 5 UNION ALL
SELECT 6 UNION ALL
SELECT 1 UNION ALL
SELECT 12
--利用递归实现输出三月份的所有日期:
select coalesce(min(a.id)+1,1) as id
from tbl a where not exists (select 1 from tbl b
where b.id=a.id+1) and exists (
select 1 from tbl where id=1
)
/*
id
2
*/