SELECT
--DISTINCT
organizations.Name,users.FName, users.LName, UserTypes.Name, users.Email, Users.id,
(SELECT COUNT(MessageId)) As MsgsReceived,
(SELECT COUNT(MessageID)
WHERE Messages.Urgency = 1) AS LowMsgsReceived,
(SELECT COUNT(MessageID)
WHERE Messages.Urgency = 2) AS MedMsgsReceived,
(SELECT COUNT(MessageID)
WHERE Messages.Urgency = 3) AS HighMsgsReceived
FROM Users
INNER JOIN Recipients ON
Users.ID = Recipients.UserId
INNER JOIN Messages ON
Messages.ID = Recipients.MessageID
INNER JOIN UserTypes ON
Users.UserTypeID = UserTypes.ID
INNER JOIN Organizations ON
Users.OrganizationId = Organizations.Id
GROUP BY organizations.Name,users.FName, users.LName, UserTypes.Name, users.Email, Users.id, Messages.Urgency
ORDER BY Users.FName
计数给了我收到的消息级别的错误结果。下面的查询给了我正确的计数,但有些行我不想在上面显示 null,而是显示 0,有什么帮助吗?