-
Notifications
You must be signed in to change notification settings - Fork 2
/
amazon_ads__campaign_report.sql
59 lines (49 loc) · 1.48 KB
/
amazon_ads__campaign_report.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{{ config(enabled=var('ad_reporting__amazon_ads_enabled', True)) }}
with report as (
select *
from {{ var('campaign_level_report') }}
),
account_info as (
select *
from {{ var('profile') }}
where _fivetran_deleted = False
),
portfolios as (
select *
from {{ ref('int_amazon_ads__portfolio_history') }}
),
campaigns as (
select *
from {{ var('campaign_history') }}
where is_most_recent_record = True
),
fields as (
select
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
campaigns.campaign_name,
report.campaign_id,
report.campaign_bidding_strategy,
report.campaign_budget_amount,
report.campaign_budget_currency_code,
report.campaign_budget_type,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='amazon_ads__campaign_passthrough_metrics', transform='sum') }}
from report
left join campaigns
on campaigns.campaign_id = report.campaign_id
left join portfolios
on portfolios.portfolio_id = campaigns.portfolio_id
left join account_info
on account_info.profile_id = campaigns.profile_id
{{ dbt_utils.group_by(13) }}
)
select *
from fields