SQL SERVER, , :
(SQL SERVER, , ...): http://sqlfiddle.com/#!3/8b9748/2
WITH zeroThruNine AS (SELECT 0 AS n UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9),
nums AS (SELECT 10*b.n+a.n AS n FROM zeroThruNine a, zeroThruNine b),
Dates AS (
SELECT DATEADD(d,n.n,(SELECT MIN(t.EntryDate) FROM @tbl t)) AS Date
FROM nums n
WHERE DATEADD(d,n.n,(SELECT MIN(t.EntryDate) FROM @tbl t))<=(SELECT MAX(t.EntryDate) FROM @tbl t)
), Data AS (
SELECT d.Date, t.ObjID, t.State, ROW_NUMBER() OVER (PARTITION BY t.ObjID, d.Date ORDER BY t.EntryDate DESC) as r
FROM Dates d, @tbl t
WHERE d.Date>=t.EntryDate
)
SELECT t.Date, t.State, COUNT(*)
FROM Data t
WHERE t.r=1
GROUP BY t.Date, t.State
ORDER BY t.Date, t.State
(. http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-numbers-table.html). , WITH, , - 0 99. , , , 100 ( 100 , )
, CTE, Data CTE
cte @tbl ( ) , . , / . , WHERE t.r = 1,
, , , , . , 0,