Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT st.*,
- SUM(coalesce(st.media_spend / st.mobile_conversions, 0)) AS cost_per_mobile_conversion,
- SUM(coalesce(st.media_spend / st.mobile_conversion_installs, 0)) AS cost_per_install,
- SUM(coalesce(st.media_spend / st.app_clicks, 0)) AS cost_per_app_click,
- SUM(coalesce(st.media_spend / st.follows, 0)) AS cost_per_follow,
- SUM(coalesce(st.media_spend / st.qualified_impressions, 0)) AS cost_per_qualified_impression,
- SUM(coalesce(st.media_spend / st.engagements, 0)) AS cost_per_engagement,
- SUM(coalesce(st.media_spend / st.retweets, 0)) AS cost_per_retweet,
- SUM(coalesce(st.media_spend / st.clicks, 0)) AS cost_per_click,
- SUM(coalesce(st.media_spend / st.impressions, 0)) AS cost_per_impression,
- SUM(coalesce(st.clicks / st.impressions, 0)) AS click_thru_rate,
- SUM(coalesce(st.media_spend / st.media_views, 0)) AS cost_per_media_view,
- SUM(coalesce(st.media_spend / st.video_total_views, 0)) AS cost_per_video_view,
- SUM(coalesce(st.video_total_views / st.impressions, 0)) AS video_view_rate,
- SUM(coalesce(st.url_clicks / st.impressions, 0)) AS click_rate,
- SUM(coalesce(st.media_spend / st.url_clicks, 0)) AS cost_per_link_click,
- SUM(coalesce(st.media_spend / st.web_conversions, 0)) AS cost_per_conversion
- FROM
- (SELECT
- to_char(st.start_time, 'YYYY-MM-DD') date,
- st.id campaign_id,
- twc.name campaign_name,
- SUM(coalesce(st.impressions, 0)) impressions,
- SUM(coalesce(st.qualified_impressions, 0)) qualified_impressions,
- SUM(coalesce(st.app_clicks, 0)) app_clicks,
- SUM(coalesce(st.clicks, 0)) clicks,
- SUM(coalesce(st.url_clicks, 0)) url_clicks,
- SUM(coalesce(st.replies, 0)) replies,
- SUM(coalesce(st.retweets, 0)) retweets,
- SUM(coalesce(st.likes, 0)) likes,
- SUM(coalesce(st.follows, 0)) follows,
- SUM(coalesce(st.card_engagements, 0)) leads,
- SUM(coalesce(st.video_total_views, 0)) video_total_views,
- SUM(coalesce(st.video_content_starts, 0)) video_content_starts,
- SUM(coalesce(st.billed_charge_local_micro :: FLOAT, 0) /1000000.0) media_spend,
- SUM(coalesce(st.conversion_downloads__metric, 0)) conversion_downloads,
- SUM(coalesce(st.conversion_sign_ups__metric, 0)) conversion_sign_ups,
- SUM(coalesce(st.conversion_site_visits__metric, 0)) conversion_site_visits,
- SUM(coalesce(st.conversion_purchases__metric, 0)) conversion_purchases,
- SUM(coalesce(CAST(st.conversion_custom__metric AS INT), 0)
- + coalesce(st.conversion_site_visits__metric, 0)
- + coalesce(st.conversion_sign_ups__metric, 0)
- + coalesce(st.conversion_downloads__metric, 0)
- + coalesce(st.conversion_purchases__metric, 0)) conversions,
- SUM(coalesce(st.engagements, 0)) engagements,
- SUM(coalesce(st.video_cta_clicks, 0)) video_cta_clicks,
- SUM(coalesce(st.video_views_25, 0)) video_views_25,
- SUM(coalesce(st.video_views_50, 0)) video_views_50,
- SUM(coalesce(st.video_views_75, 0)) video_views_75,
- SUM(coalesce(st.video_views_100, 0)) video_views_100,
- SUM(coalesce(st.video_3s100pct_views, 0)) video_full_views,
- SUM(coalesce(CAST(st.conversion_custom__metric AS INT),0)) conversion_custom,
- SUM(coalesce(st.conversion_downloads__metric, 0)) conversion_downloads,
- SUM(coalesce(st.conversion_purchases__order_quantity, 0)) conversion_order_quantity,
- SUM(coalesce(st.conversion_purchases__metric, 0)) conversion_purchases,
- SUM(coalesce(st.conversion_purchases__sale_amount, 0)) conversion_sale_amount,
- SUM(coalesce(st.conversion_sign_ups__metric, 0)) conversion_sign_ups,
- SUM(coalesce(st.conversion_site_visits__metric, 0)) conversion_site_visits,
- SUM(coalesce(st.billed_charge_local_micro, 0)) billed_charge_local_micro,
- SUM(coalesce(st.mobile_conversion_achievements_unlocked__assisted, 0)
- + coalesce(st.mobile_conversion_achievements_unlocked__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_achievements_unlocked__post_view,
- 0)) mobile_conversion_achievement_unlocked,
- SUM(coalesce(st.mobile_conversion_payment_info_additions__assisted, 0)
- + coalesce(st.mobile_conversion_payment_info_additions__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_payment_info_additions__post_view,
- 0)) mobile_conversion_added_payment_infos,
- SUM(coalesce(st.mobile_conversion_add_to_carts__assisted, 0)
- + coalesce(st.mobile_conversion_add_to_carts__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_add_to_carts__post_view,
- 0)) mobile_conversion_add_to_cart,
- SUM(coalesce(st.mobile_conversion_add_to_wishlists__assisted, 0)
- + coalesce(st.mobile_conversion_add_to_wishlists__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_add_to_wishlists__post_view,
- 0)) mobile_conversion_add_to_wishlist,
- SUM(coalesce(st.mobile_conversion_checkouts_initiated__assisted, 0)
- + coalesce(st.mobile_conversion_checkouts_initiated__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_checkouts_initiated__post_view,
- 0)) mobile_conversion_checkout_initiated,
- SUM(coalesce(st.mobile_conversion_content_views__assisted, 0)
- + coalesce(st.mobile_conversion_content_views__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_content_views__post_view,
- 0)) mobile_conversion_content_views,
- SUM(coalesce(st.mobile_conversion_installs__assisted, 0)
- + coalesce(st.mobile_conversion_installs__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_installs__post_view,
- 0)) mobile_conversion_installs,
- SUM(coalesce(st.mobile_conversion_invites__assisted, 0)
- + coalesce(st.mobile_conversion_invites__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_invites__post_view,
- 0)) mobile_conversion_invites,
- SUM(coalesce(st.mobile_conversion_levels_achieved__assisted, 0)
- + coalesce(st.mobile_conversion_levels_achieved__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_levels_achieved__post_view,
- 0)) mobile_conversion_level_achieved,
- SUM(coalesce(st.mobile_conversion_logins__assisted, 0)
- + coalesce(st.mobile_conversion_logins__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_logins_credits__post_view,
- 0)) mobile_conversion_logins,
- SUM(coalesce(st.mobile_conversion_rates__assisted, 0)
- + coalesce(st.mobile_conversion_rates__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_rates__post_view,
- 0)) mobile_conversion_rates,
- SUM(coalesce(st.mobile_conversion_re_engages__assisted, 0)
- + coalesce(st.mobile_conversion_re_engages__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_re_engages__post_view,
- 0)) mobile_conversion_re_engages,
- SUM(coalesce(st.mobile_conversion_reservations__assisted, 0)
- + coalesce(st.mobile_conversion_reservations__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_reservations__post_view,
- 0)) mobile_conversion_reservations,
- SUM(coalesce(st.mobile_conversion_searches__assisted, 0)
- + coalesce(st.mobile_conversion_searches__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_searches__post_view,
- 0)) mobile_conversion_searches,
- SUM(coalesce(st.mobile_conversion_spent_credits__assisted, 0)
- + coalesce(st.mobile_conversion_spent_credits__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_spent_credits__post_view,
- 0)) mobile_conversion_spent_credits,
- SUM(coalesce(st.mobile_conversion_tutorials_completed__assisted, 0)
- + coalesce(st.mobile_conversion_tutorials_completed__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_tutorials_completed__post_view,
- 0)) mobile_conversion_tutorial_completes,
- SUM(coalesce(st.mobile_conversion_updates__assisted, 0)
- + coalesce(st.mobile_conversion_updates__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_updates__post_view,
- 0)) mobile_conversion_updates,
- SUM(coalesce(st.mobile_conversion_shares__assisted, 0)
- + coalesce(st.mobile_conversion_shares__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_shares__post_view,
- 0)) mobile_conversion_shares,
- SUM(coalesce(st.mobile_conversion_key_page_views__assisted, 0)
- + coalesce(st.mobile_conversion_key_page_views__post_engagement,
- 0)
- + coalesce(st.mobile_conversion_key_page_views__post_view,
- 0)) mobile_conversion_key_page_views,
- SUM(coalesce(st.media_views, 0)) media_views,
- SUM(coalesce(st.mobile_conversion_achievements_unlocked__assisted, 0)
- + coalesce(st.mobile_conversion_achievements_unlocked__post_engagement, 0)
- + coalesce(st.mobile_conversion_achievements_unlocked__post_view, 0)
- + coalesce(st.mobile_conversion_add_to_carts__assisted, 0)
- + coalesce(st.mobile_conversion_add_to_carts__post_engagement, 0)
- + coalesce(st.mobile_conversion_add_to_carts__post_view, 0)
- + coalesce(st.mobile_conversion_add_to_wishlists__assisted, 0)
- + coalesce(st.mobile_conversion_add_to_wishlists__post_engagement, 0)
- + coalesce(st.mobile_conversion_add_to_wishlists__post_view, 0)
- + coalesce(st.mobile_conversion_checkouts_initiated__assisted, 0)
- + coalesce(st.mobile_conversion_checkouts_initiated__post_engagement, 0)
- + coalesce(st.mobile_conversion_checkouts_initiated__post_view, 0)
- + coalesce(st.mobile_conversion_content_views__assisted, 0)
- + coalesce(st.mobile_conversion_content_views__post_engagement, 0)
- + coalesce(st.mobile_conversion_content_views__post_view, 0)
- + coalesce(st.mobile_conversion_invites__assisted, 0)
- + coalesce(st.mobile_conversion_invites__post_engagement, 0)
- + coalesce(st.mobile_conversion_invites__post_view, 0)
- + coalesce(st.mobile_conversion_key_page_views__assisted, 0)
- + coalesce(st.mobile_conversion_key_page_views__post_engagement, 0)
- + coalesce(st.mobile_conversion_key_page_views__post_view, 0)
- + coalesce(st.mobile_conversion_levels_achieved__assisted, 0)
- + coalesce(st.mobile_conversion_levels_achieved__post_engagement, 0)
- + coalesce(st.mobile_conversion_levels_achieved__post_view, 0)
- + coalesce(st.mobile_conversion_logins__assisted, 0)
- + coalesce(st.mobile_conversion_logins__post_engagement, 0)
- + coalesce(st.mobile_conversion_logins_credits__post_view, 0)
- + coalesce(st.mobile_conversion_rates__assisted, 0)
- + coalesce(st.mobile_conversion_rates__post_engagement, 0)
- + coalesce(st.mobile_conversion_rates__post_view, 0)
- + coalesce(st.mobile_conversion_re_engages__assisted, 0)
- + coalesce(st.mobile_conversion_re_engages__post_engagement, 0)
- + coalesce(st.mobile_conversion_re_engages__post_view, 0)
- + coalesce(st.mobile_conversion_reservations__assisted, 0)
- + coalesce(st.mobile_conversion_reservations__post_engagement, 0)
- + coalesce(st.mobile_conversion_reservations__post_view, 0)
- + coalesce(st.mobile_conversion_searches__assisted, 0)
- + coalesce(st.mobile_conversion_searches__post_engagement, 0)
- + coalesce(st.mobile_conversion_searches__post_view, 0)
- + coalesce(st.mobile_conversion_shares__assisted, 0)
- + coalesce(st.mobile_conversion_shares__post_engagement, 0)
- + coalesce(st.mobile_conversion_shares__post_view, 0)
- + coalesce(st.mobile_conversion_spent_credits__assisted, 0)
- + coalesce(st.mobile_conversion_spent_credits__post_engagement, 0)
- + coalesce(st.mobile_conversion_spent_credits__post_view, 0)
- + coalesce(st.mobile_conversion_tutorials_completed__assisted, 0)
- + coalesce(st.mobile_conversion_tutorials_completed__post_engagement, 0)
- + coalesce(st.mobile_conversion_tutorials_completed__post_view, 0)
- + coalesce(st.mobile_conversion_updates__assisted, 0)
- + coalesce(st.mobile_conversion_updates__post_engagement, 0)
- + coalesce(st.mobile_conversion_updates__post_view, 0)
- + coalesce(st.mobile_conversion_payment_info_additions__assisted, 0)
- + coalesce(st.mobile_conversion_payment_info_additions__post_engagement, 0)
- + coalesce(st.mobile_conversion_payment_info_additions__post_view, 0)
- + coalesce(st.mobile_conversion_installs__assisted, 0)
- + coalesce(st.mobile_conversion_installs__post_engagement, 0)
- + coalesce(st.mobile_conversion_installs__post_view, 0)) mobile_conversions,
- 0 mobile_conversion_order_quantity,
- 0 mobile_conversion_purchases,
- 0 mobile_conversion_sale_amount_local_micro,
- 0 mobile_conversion_sign_ups,
- SUM(coalesce(st.web_conversions, 0)) conversions,
- SUM(coalesce(st.card_engagements, 0)) card_engagements
- FROM
- twitter_campaign_stats st
- INNER JOIN
- twitter_campaigns twc ON st.id = twc.campaign_id
- WHERE
- st.id = ANY(ARRAY['2s4jk']) AND st.placement IS NOT NULL
- and st.start_time between '2015-01-01' and '2016-06-30 23:59:59.999999'
- GROUP BY
- st.start_time, st.id, twc.name
- ORDER BY st.start_time, st.id
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement