我正在尝试累积 SQL Server 运输系统中事件事件数量的年初至今总数,以便在图表中显示。
我目前拥有的:
SELECT EventType.Name AS [Incident Name], COUNT(Event.ID) AS [Occurrence]
FROM Event
INNER JOIN
PortEvent ON Event.PortEventID = PortEvent.ID
INNER JOIN
EventType ON PortEvent.EventID = Event.ID
WHERE Event.IsIncident = 1 and Event.Date BETWEEN (Start of Year & Now)
GROUP BY Event.Name
这会返回什么;
Incident Name Occurrence
Incident 1 1
Incident 3 4
Incident 4 7
我想要的是:
Incident Name Occurrence
Incident 1 1
Incident 2 0
Incident 3 4
Incident 4 7
Incident 5 0
有没有办法简单地做到这一点?我看过一些关于 SO 的示例,但仅适用于相邻的表。
谢谢