-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfacebook_pages__posts_report.sql
48 lines (39 loc) · 1.13 KB
/
facebook_pages__posts_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
with posts as (
select *
from {{ ref('int_facebook_pages__lastest_post') }}
where is_most_recent_record = True
), pages as (
select *
from {{ var('pages') }}
), post_metrics as (
select *
from {{ var('post_metrics') }}
), joined as (
select
posts.created_timestamp,
posts.post_id,
posts.post_message,
posts.post_url,
posts.page_id,
pages.page_name,
post_metrics.date_day,
post_metrics.clicks,
post_metrics.impressions,
post_metrics.video_avg_time_watched,
post_metrics.video_view_time,
post_metrics.video_views,
post_metrics.video_views_10s,
post_metrics.video_views_15s,
post_metrics.reactions_like_total as likes,
post_metrics.source_relation,
post_metrics.is_most_recent_record
from post_metrics
left join posts
on post_metrics.post_id = posts.post_id
and post_metrics.source_relation = posts.source_relation
left join pages
on posts.page_id = pages.page_id
and posts.source_relation = pages.source_relation
)
select *
from joined