我设计了一个仪表板,显示一周内关闭的事件数量,但我还想要在本周末仍然开放的剩余事件数量。这是我当前的查询。如何获得剩余的未解决事件?
SELECT
ISNULL(A.[Year],B.[Year]) [Year],
ISNULL(A.[Week],B.[Week]) [Week],
ISNULL(A.Opened,0) Opened,
ISNULL(B.Closed,0) Closed,
A.totResponse, A.totCompletion
FROM (SELECT YEAR(insert_time) [Year],
DATEPART(WEEK,insert_time) [Week],
COUNT(id) Opened, sum(timer2) totResponse, sum(timer1) AS totCompletion
FROM service_req
WHERE [insert_time] IS NOT NULL and sr_type=1
GROUP BY YEAR(insert_time), DATEPART(WEEK,insert_time)) A
FULL JOIN ( SELECT YEAR(close_time) [Year],
DATEPART(WEEK,close_time) [Week],
COUNT(id) Closed
FROM service_req
WHERE [close_time] IS NOT NULL and sr_type=1
GROUP BY YEAR(close_time), DATEPART(WEEK,close_time)) B
ON A.[Year] = B.[Year] AND A.[Week] = B.[Week]
ORDER BY [Year], [Week]