I'm trying to pull together a DE that contains: total deployed, total opens, unique opens, total click, unique click, etc... There have been multiple deployments of the same email name and I'm trying to summerise the counts based on the jobid
when I run this code then opens part is duplicating, however, if I split the code it works. I can't quite work out what is wrong.
SQL Code
SELECT
t1.Total_Deployed,
t1.jobid as t1_jobid,
t2.Total_Opens,
t2.jobid as t2_jobid,
t3.Total_opens_Unique
FROM
(
SELECT
COUNT(*) AS Total_Deployed,
jobid
FROM _Sent s
JOIN (select jobid as job
from _Job where emailname ='xxxxx') j on j.job = s.jobid
WHERE s.jobid = j.job
group by jobid) as t1
cross join (SELECT
COUNT(*) as Total_opens,
jobid
FROM
(SELECT
Eventdate,
row_number()over(partition by SubscriberKey order by eventdate asc) as row,
IsUnique,
SubscriberKey,
SubscriberID,
Jobid
FROM _open o
JOIN (select jobid as job
from _Job where emailname ='xxxxx') j on j.job = o.jobid
WHERE o.jobid = j.job
GROUP BY eventdate, IsUnique, SubscriberKey,SubscriberID,jobid) x group by jobid) as t2
cross join (
SELECT
COUNT(*) as Total_opens_Unique,
jobid
FROM
(SELECT
Eventdate,
row_number()over(partition by SubscriberKey order by eventdate asc) as row,
IsUnique,
SubscriberKey,
SubscriberID,
jobid
FROM _open o
JOIN (select jobid as job
from _Job where emailname ='xxxxx'
group by jobid) j on j.job = o.jobid
WHERE o.jobid = j.job
GROUP BY eventdate, IsUnique, SubscriberKey,SubscriberID,jobid) x
Where x.row=1 group by jobid)
as t3