I want to count mails sent (master table: ex_deliverylog) & their recipients (details table: ex_deliverylog) from logs. The query below returns same values for both [session] and [recipients]. In short I couldn't group & count [session].
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
Query & result:
Tables & fields:
How can I count both sessions & their total recipients?