我想从日志中计算发送的邮件(主表:ex_deliverylog)及其收件人(详细信息表:ex_deliverylog)。下面的查询为 [session] 和 [recipients] 返回相同的值。简而言之,我无法对 [会话] 进行分组和计数。
Select
deliveryaccount,
DATEDIFF(d,deliverytime, getdate()) AS ago
,COUNT(ex_deliverylog.deliveryid) as session
,COUNT(ex_deliverylog_recipients.deliveryid) as recipients
--,( select count(*) from ex_deliverylog_recipients where ex_deliverylog.deliveryid = ex_deliverylog_recipients.deliveryid )
from ex_deliverylog
left join ex_deliverylog_recipients
on ex_deliverylog_recipients.deliveryid = ex_deliverylog.deliveryid
group by
deliveryaccount,
DATEDIFF(d,deliverytime, getdate())
order by ago, session desc
查询&结果:
表格和字段:
我如何计算两个会话及其总收件人?