Hoping to get some help with this problem.
So I performed an outer join from a table called manualdatasets.north_american_countries into a table called Sales Venue.
North American countries table has 3 rows of data in the country field (North America, US, Canada) while the Sales venue table has only two countries(US and Canada)
My goal is to sum up distinct_market data from the rows that have ('US and Canada ) as countries into the row where the country name is = 'North America' using a case statement below but being that this section has no data its coming up as 'null'.
update** I've already tried partition and it still produces a null result
Here's my query:
with sales_ven as(select sv.rn_descriptor
,sv.mkt
,sv.dma
, nac.country_name
, case when
venue_network_name in ('US Elevator', 'CAN Elevator','CAN Well Split','CAN Lobby', 'US
Well Split', 'US Lobby' ) then 'OFFICE'
when venue_network_name in ('US MFH 16:9', 'US MFH 4:3', 'CAN MFH 16:9') then
'RESIDENTIAL'
when venue_network_name = 'Windowfront' then 'WINDOWFRONT'
when venue_network_name = 'US Golf' then 'GOLF'
else null end as network_type
,case when nac.country_name in ('US', 'Canada')then count(distinct dma) over (partition by
network_type, nac.country_name)
end as distinct_dma --23
,case when nac.country_name in ('US', 'Canada') then count(distinct mkt) over (partition by network_type, country_name) end as distinct_market --24
from _sales_venue sv
full outer join fivetran.manualdatasets.north_american_countires nac on nac.country_name = sv.country
group by 1,2,3,4, 5 )
select distinct_market,
distinct dma,
country_name
case when country_name = 'North America' and network_type = 'Office' then sum(distinct_dma) else distinct_dma end as dist_dma
from sales_venue
Any insight would be great. Thanks!