You are on page 1of 1

select

x.service_group,x.a.source_id,sum(x.mbpscount),count(x.sdecount),count(x.streamcou
nt)
from
(select a.event_id,a.service_group,a.source_id,a.event_time
,a.event_type,a.viewcount,
case when a.viewcount > 0 then b.bit_rate end as mbpscount,
case when a.viewcount > 0 then b.sde end as sdecount,
case when a.viewcount > 0 then 1 end as streamcount
from
(select event_id,service_group,source_id,event_time ,event_type,count(event_type)
as viewcount from stg_srm_events
group by event_id,service_group,source_id,event_type,event_time
having event_type=1
order by service_group,source_id,event_time asc) a
inner join
(select source_id as sourceid,bit_rate,sde from stg_channels) b
on a.source_id = b.sourceid) x
group by x.service_group,x.a.source_id,x.mbpscount,x.sdecount,x.streamcount

You might also like