这是一个“功能”或“错误”,具体取决于您如何看待 ForDivision for MailmessagesSent和received中的缺失值。
通过以下查询,我确定了每个帐户发送和接收的打开邮件列表:
use select min(code) from systemdivisions where status = 1 /* Active. */ group by customercode
select mbx.accountname
, mbx.ForDivisionDescription
, mbx.ForDivision
, mrd.*
from MailMessagesReceived mrd
join mailboxes mbx
on mbx.id = mrd.recipientmailboxid
--and mbx.ForDivision = 886678
where mrd.recipientstatus in (10, 20, 25, 30) /* 10: Draft, 20: Open, 25: Prepared, 30: Approved */
您还可以按客户汇总报告它们:
select mbx.accountname
, mbx.ForDivisionDescription
, mbx.ForDivision
, count(*)
from MailMessagesReceived mrd
join mailboxes mbx
on mbx.id = mrd.recipientmailboxid
where mrd.recipientstatus in (10, 20, 25, 30) /* 10: Draft, 20: Open, 25: Prepared, 30: Approved */
group
by mbx.accountname
, mbx.ForDivisionDescription
, mbx.ForDivision
诀窍是邮箱中的 ForDivision与 Exact Online 的 MailMessagesSent/Received 具有不同的语义。
2018 版本提供了简化版本:
select mrd.RecipientMailboxCustomerName
, mrd.RecipientMailboxForDivisionDescription
, mrd.RecipientMailboxForDivision
, count(*)
from MailMessagesReceived mrd
where mrd.recipientstatus in (10, 20, 25, 30) /* 10: Draft, 20: Open, 25: Prepared, 30: Approved */
and mrd.division in ( select /*+ low_cost */ min(sdn.code) from systemdivisions sdn group by sdn.customer )
group
by mrd.RecipientMailboxCustomerName
, mrd.RecipientMailboxForDivisionDescription
, mrd.RecipientMailboxForDivision
或简称:
select mrd.RecipientMailboxCustomerName
, mrd.RecipientMailboxForDivisionDescription
, mrd.RecipientMailboxForDivision
, count(*)
from MailMessagesReceivedUnhandled mrd
group
by mrd.RecipientMailboxCustomerName
, mrd.RecipientMailboxForDivisionDescription
, mrd.RecipientMailboxForDivision