ALL Podcast Queries-Ajeet
ALL Podcast Queries-Ajeet
`music_analytics_archived.ma_track_play_log_detailed_*` p
Gaana-bigquery-1315.music_analytics.ma_podcast_data
Gaana-bigquery-1315:music_analytics.tm_offline_trackslog_18082018
Music.
Tm_podcast_seasons (table of mapping b/w shows and episodes)
Tm_track (individual tracks and podcasts (sapid==1))
Tm_podcasts_show (all show data)
Tm_vendor (list of all unique vendors)
Tm_artistF (list of all vendors Artist)
Podcast_show_tags
Tm_tag_val_master (Type I and Type II)
Tm_user_details (logged in Users info)
App cast ids (Only spoken audio pieces)
Podcast_L30
gaana-bigquery-1315:acoe_gaana.Cohort_L30
group by 1,2,3
order by date desc
Vendor details of APP cast tracks:
select show_id, show_title,
app_cast_id,a.track_id,vendor_id,vendor_name,duration,song_title,track_order,created_o
n,is_active
from (
select j.show_id as show_id, k.title as
show_title,app_cast_id,track_id,duration,track_title,
track_order,created_on,is_active
--j.tid as episode_id, i.title as episode_name,
from (
select app_cast_id,track_id,duration,track_title,track_order,created_on,is_active
from `music.tm_app_cast`
--where lower(sapid) in ('podcast')
) i
join
(
select distinct show_id, safe_cast(track_id as int64) as tid, season
from `music.tm_podcast_seasons`
) j
on safe_cast(i.app_cast_id as int64) = j.tid
left join (
select id, title
from `music.tm_podcasts_show`
) k
on safe_cast(j.show_id as int64) = k.id
--where show_id in ("1947")
) a
left join(
select i.id as track_id,i.title as song_title, j.name as vendor_name,j.id as vendor_id
--j.tid as episode_id, i.title as episode_name,
from (
select *
from `music.tm_track` --where title in ("Baghon Mein Bahar Hai")
) i
join
(
select id, name
from `music.tm_vendor`
) j
on safe_cast(i.vendor_id as int64) = j.id
) b
on safe_cast(a.track_id as int64) = b.track_id
group by 1,2,3,4,5,6,7,8,9,10,11
Music and Podcast artist count status wise:
select id, title, vendor_id, vendor_name,is_migrated,link,status
from `music.tm_podcasts_show` where vendor_name in ("Gaana Promo")
id,name,dob,gender,num_songs,num_albums,languages,popall,total_favourite_count,
select distinct (status), count (status)
US listenership data:
select
--show_id,
show_title,episode_name,--section_id,songtime_foreground,songtime_player,time_played_o
n,
--categories, language,release_date,date,
device_id,--type,--lient_country_code,--count(client_country_code) as
no_of_plays_in_each_country,
--count(distinct device_id) as total_users,
sum(plays) as total_plays,
round((sum(duration)/60),2) as total_duration_mins
from ((
select
--safe_cast(timestamp(time_played_on) as date) as
date,time_played_on,section_id,songtime_foreground,songtime_player,
device_id, cast (track_id as int64) as track_id,--client_country_code,
sum(duration) as duration, -- 'online' as type,
count(1) as plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
where (_table_suffix between format_date('%Y%m%d', date('2021-01-01')) and
format_date('%Y%m%d', date('2021-01-31')))
--and duration>30 --To take only those plays where duration > 30s
and safe_cast(track_id as int64) in (select id from `music.tm_track` where
lower(sapid) in ('podcast')) -- To take all podcast tracks ONLY
and client_country_code in ("US")
group by 1,2
)
) a
join(
select j.show_id as show_id, k.title as show_title,language, categories,
release_date,status,
j.tid as episode_id, i.title as episode_name,
from (
select id, title
from `music.tm_track`
where lower(sapid) in ('podcast')
) i
join
(
select distinct show_id, safe_cast(track_id as int64) as tid, season
from `music.tm_podcast_seasons`
) j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language,
categories,date(timestamp(created_on)) as release_date,status,
from `music.tm_podcasts_show`
) k
on safe_cast(j.show_id as int64) = k.id
) b
on a.track_id = b.episode_id
Where show_id in ("1947"
)
group by 1
Podcast Scoring 3.5 month overall performance
--Show level
select X.*,
round(overall_listening_time/(60*total_users),2) as mpu,
round(overall_listening_time/total_tracks_length,2) as completion_perc,
followers_past_week as followers_past_week,
total_podcast_show_followers as total_followers,
date_diff(end_date_1,release_date,day) as age_on_lastday
from(
select
show_id, show_title, categories, language, show_length, show_episode_count,
release_date, --popall, pop30days, pop7days,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
sum(track_length) as total_tracks_length
from (
select device_id, track_id,q.track_length,
sum(duration) as overall_listening_time,
count(1) as overall_plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
join (select DISTINCT id,safe_cast(duration as int64) as track_length from `music.tm_track`
where lower(sapid) in ('podcast')) q on p.track_id = q.id
--NEW FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as followers_past_week,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between
date_add(end_date_1,INTERVAL -7 DAY) and date_add(end_date_1,INTERVAL -1 DAY)
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
date_add(end_date_1,INTERVAL -7 DAY) and date_add(end_date_1,INTERVAL -1 DAY)
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
--TOTAL FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as total_podcast_show_followers,
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2'
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0'
group by 1
))
group by 1
)Z
on X.show_id = Z.entity_id
--Show-season level
--Podcast all users all plays performance
Declare start_date_1,end_date_1 DATE;
SET (start_date_1,end_date_1) = ('2021-01-01','2021-04-15');
select X.*,
round(overall_listening_time/(60*total_users),2) as mpu,
round(overall_listening_time/total_tracks_length,2) as completion_perc,
followers_past_week as followers_past_week,
total_podcast_show_followers as total_followers,
date_diff(end_date_1,season_start,day) as age_on_lastday
from(
select
show_id, show_title, season, categories, language, show_length, show_episode_count,
season_start, popall, pop30days, pop7days,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
sum(track_length) as total_tracks_length
from (
select device_id, track_id,q.track_length,
sum(duration) as overall_listening_time,
count(1) as overall_plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
join (select DISTINCT id,safe_cast(duration as int64) as track_length from `music.tm_track`
where lower(sapid) in ('podcast')) q on p.track_id = q.id
--NEW FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as followers_past_week,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between
date_add(end_date_1,INTERVAL -7 DAY) and date_add(end_date_1,INTERVAL -1 DAY)
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
date_add(end_date_1,INTERVAL -7 DAY) and date_add(end_date_1,INTERVAL -1 DAY)
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
--TOTAL FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as total_podcast_show_followers,
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2'
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0'
group by 1
))
group by 1
)Z
on X.show_id = Z.entity_id
select X.*,
round(overall_listening_time/(60*total_users),2) as mpu,
round(overall_listening_time/(total_users*show_length),2) as completion_perc,
followers_past_week as followers_past_week,
total_podcast_show_followers as total_followers
from(
select
show_id, show_title, season, categories, language, show_length, show_episode_count,
season_start, popall, pop30days, pop7days,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
from (
select device_id, track_id,
sum(duration) as overall_listening_time,
count(1) as overall_plays
from `music_analytics_archived.ma_track_play_log_detailed_*`
where _table_suffix between format_date('%Y%m%d', date('2021-01-01')) and
format_date('%Y%m%d', date('2021-04-13'))
and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast'))
group by 1,2
)a
join
(
select j.tid as episode_id, i.title as episode_name, i.track_length as episode_length,
j.show_id as show_id, k.title as show_title, season, language, categories, season_start,
count(j.tid) over(partition by show_id) as show_episode_count,
sum(i.track_length) over(partition by show_id) as show_length,
sum(cast(popall as int64)) over(partition by show_id) as popall,
sum(cast(pop30days as int64)) over(partition by show_id) as pop30days,
sum(cast(pop7days as int64)) over(partition by show_id) as pop7days,
from (
select id, title, safe_cast(duration as int64) as track_length, popall, pop30days, pop7days
from `music.tm_track`
where lower(sapid) in ('podcast')
)i
join
(
select distinct show_id,tid,season,MIN(release_date) Over (partition by show_id,season order
by release_date) as season_start from (
select distinct show_id, safe_cast(track_id as int64) as tid, season,
date(timestamp(created_on)) as release_date
from `music.tm_podcast_seasons` )
)j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language, categories
from `music.tm_podcasts_show`) k
on safe_cast(j.show_id as int64) = k.id
)b
on a.track_id = b.episode_id
where b.show_length <> 0 and b.season_start <= date_add(CURRENT_DATE(),INTERVAL -1
MONTH)
group by 1,2,3,4,5,6,7,8,9,10,11
)X
--NEW FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as followers_past_week,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between
date_add(CURRENT_DATE(),INTERVAL -7 DAY) and date_add(CURRENT_DATE(),INTERVAL
-1 DAY)
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
date_add(CURRENT_DATE(),INTERVAL -7 DAY) and date_add(CURRENT_DATE(),INTERVAL
-1 DAY)
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
--TOTAL FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as total_podcast_show_followers,
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2'
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0'
group by 1
))
group by 1
)Z
on X.show_id = Z.entity_id
select X.*,
round(overall_listening_time/(60*total_users),2) as mpu,
round(overall_listening_time/(total_users*show_length),2) as completion_perc,
followers_past_week as followers_past_week,
total_podcast_show_followers as total_followers
from(
select
show_id, show_title, season, categories, language, show_length, show_episode_count,
season_start, popall, pop30days, pop7days,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
from (
select device_id, track_id,
sum(duration) as overall_listening_time,
count(1) as overall_plays
from `music_analytics_archived.ma_track_play_log_detailed_*`
where _table_suffix between format_date('%Y%m%d', date('2021-01-01')) and
format_date('%Y%m%d', date('2021-04-13'))
and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast'))
and duration > 30
group by 1,2
)a
join
(
select j.tid as episode_id, i.title as episode_name, i.track_length as episode_length,
j.show_id as show_id, k.title as show_title, season, language, categories, season_start,
count(j.tid) over(partition by show_id) as show_episode_count,
sum(i.track_length) over(partition by show_id) as show_length,
sum(cast(popall as int64)) over(partition by show_id) as popall,
sum(cast(pop30days as int64)) over(partition by show_id) as pop30days,
sum(cast(pop7days as int64)) over(partition by show_id) as pop7days,
from (
select id, title, safe_cast(duration as int64) as track_length, popall, pop30days, pop7days
from `music.tm_track`
where lower(sapid) in ('podcast')
)i
join
(
select distinct show_id,tid,season,MIN(release_date) Over (partition by show_id,season order
by release_date) as season_start from (
select distinct show_id, safe_cast(track_id as int64) as tid, season,
date(timestamp(created_on)) as release_date
from `music.tm_podcast_seasons` )
)j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language, categories
from `music.tm_podcasts_show`) k
on safe_cast(j.show_id as int64) = k.id
)b
on a.track_id = b.episode_id
where b.show_length <> 0 and b.season_start <= date_add(CURRENT_DATE(),INTERVAL -1
MONTH)
group by 1,2,3,4,5,6,7,8,9,10,11
)X
--NEW FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as followers_past_week,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between
date_add(CURRENT_DATE(),INTERVAL -7 DAY) and date_add(CURRENT_DATE(),INTERVAL
-1 DAY)
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
date_add(CURRENT_DATE(),INTERVAL -7 DAY) and date_add(CURRENT_DATE(),INTERVAL
-1 DAY)
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
--TOTAL FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as total_podcast_show_followers,
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2'
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0'
group by 1
))
group by 1
)Z
on X.show_id = Z.entity_id
from (
select p.* from(
select *,
sum(pm_section_listening_time) over(partition by device_id,track_id) as overall_listening_time,
sum(pm_section_plays) over (partition by device_id,track_id) as overall_plays --getting duration
& plays from all sections for the users who visited through promoted sections
from(
select device_id, track_id, section_id,
sum(duration) as pm_section_listening_time,
count(1) as pm_section_plays
from `music_analytics_archived.ma_track_play_log_detailed_*`
where _table_suffix between format_date('%Y%m%d', date('2021-04-06')) and
format_date('%Y%m%d', date('2021-04-12'))
and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast'))
group by 1,2,3
)) p
join
(select section_id as id from `avnish.promoted_sections`
--where lower(name) like 'search%' or lower(name) like 'homecarousel%'
)q
on p.section_id = q.id
order by device_id,track_id,overall_plays desc
)a
join
(
select j.tid as episode_id, i.title as episode_name, i.track_length as episode_length,
j.show_id as show_id, k.title as show_title, language, categories, release_date,
count(j.tid) over(partition by show_id) as show_episode_count,
sum(i.track_length) over(partition by show_id) as show_length,
sum(cast(popall as int64)) over(partition by show_id) as popall,
sum(cast(pop30days as int64)) over(partition by show_id) as pop30days,
sum(cast(pop7days as int64)) over(partition by show_id) as pop7days,
from (
select id, title, safe_cast(duration as int64) as track_length, popall, pop30days, pop7days
from `music.tm_track`
where lower(sapid) in ('podcast')
)i
join (
select show_id, safe_cast(track_id as int64) as tid, season
from `music.tm_podcast_seasons`
where season = '1'
group by 1,2,3) j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language, categories, date(timestamp(created_on))
as release_date
from `music.tm_podcasts_show`) k
on safe_cast(j.show_id as int64) = k.id
)b
on a.track_id = b.episode_id
where b.show_length <> 0
group by 1,2,3,4,5,6,7,8,9,10
)X
left join
(SELECT entity_id,
sum(podcast_followers) as podcast_show_followers,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between date('2021-04-06') and
date('2021-04-12')
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
date('2021-04-06') and date('2021-04-12')
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
from (
select device_id, track_id,
sum(duration) as overall_listening_time,
count(1) as overall_plays
from `music_analytics_archived.ma_track_play_log_detailed_*`
where _table_suffix between format_date('%Y%m%d', date('2021-04-06')) and
format_date('%Y%m%d', date('2021-04-12'))
and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast'))
group by 1,2
)a
join
(
select j.tid as episode_id, i.title as episode_name, i.track_length as episode_length,
j.show_id as show_id, k.title as show_title, language, categories, release_date,
count(j.tid) over(partition by show_id) as show_episode_count,
sum(i.track_length) over(partition by show_id) as show_length,
sum(cast(popall as int64)) over(partition by show_id) as popall,
sum(cast(pop30days as int64)) over(partition by show_id) as pop30days,
sum(cast(pop7days as int64)) over(partition by show_id) as pop7days,
from (
select id, title, safe_cast(duration as int64) as track_length, popall, pop30days, pop7days
from `music.tm_track`
where lower(sapid) in ('podcast')
)i
join (
select show_id, safe_cast(track_id as int64) as tid, season
from `music.tm_podcast_seasons`
where season = '1'
group by 1,2,3) j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language, categories, date(timestamp(created_on))
as release_date
from `music.tm_podcasts_show`) k
on safe_cast(j.show_id as int64) = k.id
)b
on a.track_id = b.episode_id
where b.show_length <> 0
group by 1,2,3,4,5,6,7,8,9,10
)X
left join
(SELECT entity_id,
sum(podcast_followers) as podcast_show_followers,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between date('2021-04-06') and
date('2021-04-12')
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
date('2021-04-06') and date('2021-04-12')
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
TRENDING PODCASTS PERFORMANCE QUERY
--Trending Podcasts Show level
select X.*,
round(overall_listening_time/(60*total_users),2) as mpu,
round(overall_listening_time/total_tracks_length,2) as completion_perc,
coalesce(followers_past_week,0) as followers_past_week,
total_podcast_show_followers as total_followers,
date_diff(end_date_1,release_date,day)/30 as age_in_months,
coalesce(likes_past_week,0) as likes_past_week
from(
select
show_id, show_title, categories, language, show_length, show_episode_count,
release_date,-- popall, pop30days, pop7days,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
sum(track_length) as total_tracks_length,
sum(search_plays) as total_search_plays
from (
select device_id, track_id,q.track_length,
sum(duration) as overall_listening_time,
count(1) as overall_plays,
sum(case when (section_id in (select id from `music_analytics.tm_sections` where lower(name)
like 'searchautosuggest%')) then 1 else 0 end) as search_plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
join (select DISTINCT id,safe_cast(duration as int64) as track_length from `music.tm_track`
where lower(sapid) in ('podcast')) q on p.track_id = q.id
--and duration>30
--and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast'))
group by 1,2,3
)a
join
(
select j.show_id as show_id, k.title as show_title,language, categories, release_date,
j.tid as episode_id, i.title as episode_name, i.track_length as episode_length,
count(j.tid) over(partition by show_id) as show_episode_count,
sum(i.track_length) over(partition by show_id) as show_length,
--sum(cast(popall as int64)) over(partition by show_id) as popall,
--sum(cast(pop30days as int64)) over(partition by show_id) as pop30days,
--sum(cast(pop7days as int64)) over(partition by show_id) as pop7days,
from (
select id, title, safe_cast(duration as int64) as track_length--, popall, pop30days, pop7days
from `music.tm_track`
where lower(sapid) in ('podcast')
)i
join
(
select distinct show_id, safe_cast(track_id as int64) as tid, season
from `music.tm_podcast_seasons`
)j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language, categories,date(timestamp(created_on)) as
release_date
from `music.tm_podcasts_show`
)k
on safe_cast(j.show_id as int64) = k.id
)b
on a.track_id = b.episode_id
where b.show_length <> 0 and b.release_date < season_start_1
group by 1,2,3,4,5,6,7
)X
--NEW FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as followers_past_week,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between start_date_1 and
end_date_1
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
start_date_1 and end_date_1
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
--TOTAL FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as total_podcast_show_followers,
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2'
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0'
group by 1
))
group by 1
)Z
on X.show_id = Z.entity_id
--NEW LIKES
left join
(SELECT show_id,
sum(podcast_likes) as likes_past_week
from
((
SELECT entity_id, count(*) as podcast_likes, 'loggedin' as type
FROM `gaana_favourite.tm_user_episode_*`
WHERE cast(entity_status as int64) > 1 and date(timestamp(created_on)) between
start_date_1 and end_date_1
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_likes, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_episode_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
start_date_1 and end_date_1
group by 1
)) track_likes
join
(select distinct show_id, safe_cast(track_id as int64) as tid
from `music.tm_podcast_seasons`) maps
on cast(track_likes.entity_id as int64) = maps.tid
group by 1
) AA
on X.show_id = AA.show_id
select X.*,
round(overall_listening_time/(60*total_users),2) as mpu,
round(overall_listening_time/total_tracks_length,2) as completion_perc,
followers_past_week as followers_past_week,
total_podcast_show_followers as total_followers,
date_diff(start_date_1,season_start,day) as age_on_weekstart,
date_diff(start_date_1,season_start,day)/30 as age_in_months,
likes_past_week
from(
select
show_id, show_title, season, categories, language, show_length, show_episode_count,
season_start, popall, pop30days, pop7days,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
sum(track_length) as total_tracks_length,
sum(search_plays) as total_search_plays
from (
select device_id, track_id,q.track_length,
sum(duration) as overall_listening_time,
count(1) as overall_plays,
sum(case when (section_id in (select id from `music_analytics.tm_sections` where lower(name)
like 'searchautosuggest%')) then 1 else 0 end) as search_plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
join (select DISTINCT id,safe_cast(duration as int64) as track_length from `music.tm_track`
where lower(sapid) in ('podcast')) q on p.track_id = q.id
--and duration>30
--and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast'))
group by 1,2,3
)a
join
(
select j.tid as episode_id, i.title as episode_name, i.track_length as episode_length,
j.show_id as show_id, k.title as show_title, season, language, categories, season_start,
count(j.tid) over(partition by show_id,season) as show_episode_count,
sum(i.track_length) over(partition by show_id,season) as show_length,
sum(cast(popall as int64)) over(partition by show_id,season) as popall,
sum(cast(pop30days as int64)) over(partition by show_id,season) as pop30days,
sum(cast(pop7days as int64)) over(partition by show_id,season) as pop7days,
from (
select id, title, safe_cast(duration as int64) as track_length, popall, pop30days, pop7days
from `music.tm_track`
where lower(sapid) in ('podcast')
)i
join
(
select distinct show_id,tid,season,MIN(release_date) Over (partition by show_id,season order
by release_date) as season_start from (
select distinct show_id, safe_cast(track_id as int64) as tid, season,
date(timestamp(created_on)) as release_date
from `music.tm_podcast_seasons` )
)j
on i.id = j.tid
left join (
select id, title, trim(lower(language)) as language, categories
from `music.tm_podcasts_show`) k
on safe_cast(j.show_id as int64) = k.id
)b
on a.track_id = b.episode_id
where b.show_length <> 0 and b.season_start < season_start_1
group by 1,2,3,4,5,6,7,8,9,10,11
)X
--NEW FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as followers_past_week,
sum(case when type = 'loggedin' then podcast_followers end) as
podcast_show_followers_loggedin,
sum(case when type = 'non-loggedin' then podcast_followers end) as
podcast_show_followers_non_loggedin
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2' and date(timestamp(created_on)) between start_date_1 and
end_date_1
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
start_date_1 and end_date_1
group by 1
))
group by 1
)Y
on X.show_id = Y.entity_id
--TOTAL FOLLOWERS
left join
(SELECT entity_id,
sum(podcast_followers) as total_podcast_show_followers,
from
((
SELECT entity_id, count(*) as podcast_followers, 'loggedin' as type
FROM `gaana_favourite.tm_user_podcast_*`
WHERE entity_status = '2'
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_followers, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_podcast_*`
WHERE entity_status = '2' and sync_status = '0'
group by 1
))
group by 1
)Z
on X.show_id = Z.entity_id
--NEW LIKES
left join
(SELECT show_id,season,
sum(podcast_likes) as likes_past_week
from
((
SELECT entity_id, count(*) as podcast_likes, 'loggedin' as type
FROM `gaana_favourite.tm_user_episode_*`
WHERE cast(entity_status as int64) > 1 and date(timestamp(created_on)) between
start_date_1 and end_date_1
group by 1
)
union all
(
SELECT entity_id, count(*) as podcast_likes, 'non-loggedin' as type
FROM `gaana_favourite.tm_device_episode_*`
WHERE entity_status = '2' and sync_status = '0' and date(timestamp(created_on)) between
start_date_1 and end_date_1
group by 1
)) track_likes
join
(select distinct show_id, safe_cast(track_id as int64) as tid, season
from `music.tm_podcast_seasons`) maps
on cast(track_likes.entity_id as int64) = maps.tid
group by 1,2
) AA
on X.show_id = AA.show_id and X.season = AA.season
select p.*,rr.*,t.name
from
flatten((
SELECT integer(split(podcasts, ',')) as podcast_id, integer(lang_id) as lang_id
FROM [gaana-bigquery-1315:music.tm_gpd_lang_summary]
where is_active = '1'
), podcast_id) p
left join
[music.tm_language] t
on t.id = p.lang_id
left join (
select id, title, categories
from [music.tm_podcasts_show]) rr
on p.podcast_id = rr.id
group by 1,2,3
order by 5 desc) bb
on aa.date = bb.date and aa.show_id = bb.show_id and aa.season = bb.season
order by 1,2,3 desc
select
show_id, show_title, season, categories, language, show_length, show_episode_count,
season_start,
case
when date_diff(date,season_start,day)<=30 then '1'
when date_diff(date,season_start,day)>30 and date_diff(date,season_start,day)<=60 then '2'
when date_diff(date,season_start,day)>60 and date_diff(date,season_start,day)<=90 then '3'
when date_diff(date,season_start,day)>90 and date_diff(date,season_start,day)<=120 then '4'
when date_diff(date,season_start,day)>120 and date_diff(date,season_start,day)<=150 then '5'
else '5+'
end as months_after_release,
count(distinct device_id) as total_users,
sum(overall_plays) as overall_plays,
sum(overall_listening_time) as overall_listening_time,
from (
select date(timestamp(time_played_on)) as date,
device_id, track_id,
sum(duration) as overall_listening_time,
count(1) as overall_plays,
from `music_analytics_archived.ma_track_play_log_detailed_*` p
with table1 as (
select month,section_id,user_id, email, dob, sex, fullname,
row_number() over(PARTITION BY section_id,month ORDER BY
round((sum(duration)/3600),2) DESC) AS rank1,
sum(plays) as total_plays,
round((sum(duration)/3600),2) as total_duration_Hrs
from (
select format_date('%Y%m',cast(timestamp(time_played_on) as date)) as month,
user_id, section_id,
Sum (cast (duration as Float64))as duration,
count(1) as plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
--select date range as required
where (_table_suffix between format_date('%Y%m%d', date('2021-08-1')) and
format_date('%Y%m%d', date('2021-09-30')))
and section_id in (4992,21006,21014,1020,18063,13845) and user_id NOT IN (0)
--and cast (duration as Float64)>15 --To take only those plays where duration > 30s
and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast')) --
To take all podcast tracks ONLY
group by 1,2,3
) a
join(
select id,fullname,email,sex,dob from music.tm_users
) b
on safe_cast(a.user_id as int64) = b.id
group by 1,2,3,4,5,6,7
)
select * from table1 where rank1 <=200
select date1,
row_number() over(PARTITION BY date1 ORDER BY round((sum(duration)/3600),2) DESC) AS
rank1,
sum(plays) as total_plays,
count (distinct user_id) as users,
round((sum(duration)/3600),2) as total_duration_Hrs
from (
select safe_cast(timestamp(time_played_on) as date) as date1,
user_id, section_id,
Sum (cast (duration as Float64))as duration,
count(1) as plays
from `music_analytics_archived.ma_track_play_log_detailed_*` p
--select date range as required
where (_table_suffix between format_date('%Y%m%d', date('2021-10-1')) and
format_date('%Y%m%d', date('2021-10-24')))
and user_id IN (select distinct user_id from
`music_analytics_archived.ma_track_play_log_detailed_*` p
where (_table_suffix between format_date('%Y%m%d', date('2021-10-1')) and
format_date('%Y%m%d', date('2021-10-24')))
and section_id in (39312) )
--and cast (duration as Float64)>15 --To take only those plays where duration > 30s
and track_id in (select id from `music.tm_track` where lower(sapid) in ('podcast')) --
To take all podcast tracks ONLY
and page_id in (2933,3031)
group by 1,2,3
)group by 1
order by date1 ASC