Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Commit

Permalink
fixed coupons model to eliminate duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
jthandy committed Feb 8, 2017
1 parent 5c8b238 commit 91cef11
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions models/transform/stripe_coupons.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ with events as (

select * from {{ref('stripe_coupon_events')}}

), deleted_coupons as (

select id, created_at as deleted_at
from events
where event_type = 'coupon.deleted'

)

select distinct
events.id,
first_value(created_at) over
first_value(case when event_type != 'coupon.deleted' then created_at end) over
(partition by events.id order by created_at rows between unbounded preceding and unbounded following)
as created_at,
last_value(currency) over
Expand All @@ -39,7 +33,7 @@ select distinct
last_value(valid) over
(partition by events.id order by created_at rows between unbounded preceding and unbounded following)
as valid,
deleted_coupons.deleted_at
last_value(case when event_type = 'coupon.deleted' then created_at end ignore nulls) over
(partition by events.id order by created_at rows between unbounded preceding and unbounded following)
as deleted_at
from events
left outer join deleted_coupons on events.id = deleted_coupons.id
where event_type != 'coupon.deleted'

0 comments on commit 91cef11

Please sign in to comment.