sql="select '0-7' as label,count(distinct(device_id)) from data_feed_exposure2\
sql="select '0-7' as label,count(distinct(device_id)) from data_feed_exposure \
where device_type{0} \
where device_type{0} \
and stat_date = '{7}' \
and stat_date = '{7}' \
and device_id not in \
and device_id not in \
(select distinct(device_id) from data_feed_click2\
(select distinct(device_id) from data_feed_click \
where stat_date = '{7}' \
where stat_date = '{7}' \
and device_type{1}) \
and device_type{1}) \
and device_id in \
and device_id in \
(select distinct(device_id) \
(select distinct(device_id) \
from data_feed_exposure2\
from data_feed_exposure \
where device_id not in \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {2})) \
where stat_date < {2})) \
union all \
union all \
select '7-14' as label,count(distinct(device_id)) from data_feed_exposure2\
select '7-14' as label,count(distinct(device_id)) from data_feed_exposure \
where device_type{0} \
where device_type{0} \
and stat_date = '{7}' \
and stat_date = '{7}' \
and device_id not in \
and device_id not in \
(select distinct(device_id) from data_feed_click2\
(select distinct(device_id) from data_feed_click \
where stat_date = '{7}' \
where stat_date = '{7}' \
and device_type{1}) \
and device_type{1}) \
and device_id in \
and device_id in \
(select distinct(device_id) \
(select distinct(device_id) \
from data_feed_exposure2\
from data_feed_exposure \
where device_id not in \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {3}) \
where stat_date < {3}) \
and device_id in \
and device_id in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {2})) \
where stat_date < {2})) \
union all \
union all \
select '14-30' as label,count(distinct(device_id)) from data_feed_exposure2\
select '14-30' as label,count(distinct(device_id)) from data_feed_exposure \
where device_type{0} \
where device_type{0} \
and stat_date = '{7}' \
and stat_date = '{7}' \
and device_id not in \
and device_id not in \
(select distinct(device_id) from data_feed_click2\
(select distinct(device_id) from data_feed_click \
where stat_date = '{7}' \
where stat_date = '{7}' \
and device_type{1}) \
and device_type{1}) \
and device_id in \
and device_id in \
(select distinct(device_id) \
(select distinct(device_id) \
from data_feed_exposure2\
from data_feed_exposure \
where device_id not in \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {4}) \
where stat_date < {4}) \
and device_id in \
and device_id in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {3})) \
where stat_date < {3})) \
union all \
union all \
select '30-60' as label,count(distinct(device_id)) from data_feed_exposure2\
select '30-60' as label,count(distinct(device_id)) from data_feed_exposure \
where device_type{0} \
where device_type{0} \
and stat_date = '{7}' \
and stat_date = '{7}' \
and device_id not in \
and device_id not in \
(select distinct(device_id) from data_feed_click2\
(select distinct(device_id) from data_feed_click \
where stat_date = '{7}' \
where stat_date = '{7}' \
and device_type{1}) \
and device_type{1}) \
and device_id in \
and device_id in \
(select distinct(device_id) \
(select distinct(device_id) \
from data_feed_exposure2\
from data_feed_exposure \
where device_id not in \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {5}) \
where stat_date < {5}) \
and device_id in \
and device_id in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {4})) \
where stat_date < {4})) \
union all \
union all \
select '60-90' as label,count(distinct(device_id)) from data_feed_exposure2\
select '60-90' as label,count(distinct(device_id)) from data_feed_exposure \
where device_type{0} \
where device_type{0} \
and stat_date = '{7}' \
and stat_date = '{7}' \
and device_id not in \
and device_id not in \
(select distinct(device_id) from data_feed_click2\
(select distinct(device_id) from data_feed_click \
where stat_date = '{7}' \
where stat_date = '{7}' \
and device_type{1}) \
and device_type{1}) \
and device_id in \
and device_id in \
(select distinct(device_id) \
(select distinct(device_id) \
from data_feed_exposure2\
from data_feed_exposure \
where device_id not in \
where device_id not in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {6}) \
where stat_date < {6}) \
and device_id in \
and device_id in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {5})) \
where stat_date < {5})) \
union all \
union all \
select '90+' as label,count(distinct(device_id)) from data_feed_exposure2\
select '90+' as label,count(distinct(device_id)) from data_feed_exposure \
where device_type{0} \
where device_type{0} \
and stat_date = '{7}' \
and stat_date = '{7}' \
and device_id not in \
and device_id not in \
(select distinct(device_id) from data_feed_click2\
(select distinct(device_id) from data_feed_click \
where stat_date = '{7}' \
where stat_date = '{7}' \
and device_type{1}) \
and device_type{1}) \
and device_id in \
and device_id in \
(select distinct(device_id) \
(select distinct(device_id) \
from data_feed_exposure2\
from data_feed_exposure \
where device_id in \
where device_id in \
(select distinct(device_id) from data_feed_exposure2\
(select distinct(device_id) from data_feed_exposure \
where stat_date < {6}))".format(platform,platform.replace(' ','')ifplatform[-2]=='e'elseplatform,my_date1,my_date2,my_date3,my_date4,my_date5,get_yesterday_date())
where stat_date < {6}))".format(platform,platform.replace(' ','')ifplatform[-2]=='e'elseplatform,my_date1,my_date2,my_date3,my_date4,my_date5,get_yesterday_date())