日期:2014-05-17 浏览次数:20552 次
DECLARE @date date;
set @date='2013-01-08'
;WITH t1 ( ADate , CDate ) AS (
SELECT '2013-01-01','2013-01-01' union all
SELECT '2013-01-01','2013-01-05' union all
SELECT '2013-01-02','2013-01-03' union all
SELECT '2013-01-02','2013-01-08' union all
SELECT '2013-01-03','2013-01-05' union all
SELECT '2013-01-03','2013-01-04' union all
SELECT '2013-01-05','2013-01-05' union all
SELECT '2013-01-05','2013-01-06' union all
SELECT '2013-01-05', NULL union all
SELECT '2013-01-05','2013-01-05' union all
SELECT '2013-01-06','2013-01-06' union all
SELECT '2013-01-06','2013-01-08' union all
SELECT '2013-01-07', NULL union all
SELECT '2013-01-07', NULL union all
SELECT '2013-01-07','2013-01-07'
)
Select COUNT(*) from t1 where (CDate > @date and ADate <= @date) or (CDate is null and ADate <= @date)
-- ADate 申请日期,CDate 审核日期,null表示还未审核, 算出每天总未审核的数量,算法为当前未审核的数量加上以前未审核的数量之和。
--假如截止日期为2013-01-08 结果为:
/*
申请日期 未审核总数
2013-01-01 1
2013-01-02 3
2013-01-03 4
2013-01-04 3
2013-01-05 3
2013-01-06 3
2013-01-07 5
2013-01-08 3
*/