-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new all coupons table to marts (#1493)
* add new all coupons table to marts and added two columns to orders mart
- Loading branch information
1 parent
75a7091
commit ae20ced
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/ol_dbt/models/marts/mitxpro/marts__mitxpro_all_coupons.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
with allcoupons as ( | ||
select * | ||
from {{ ref('int__mitxpro__ecommerce_allcoupons') }} | ||
) | ||
|
||
, allorders as ( | ||
select * | ||
from {{ ref('int__mitxpro__ecommerce_allorders') }} | ||
) | ||
|
||
, redeemed_coupons as ( | ||
select coupon_id | ||
from allorders | ||
where redeemed = true | ||
group by coupon_id | ||
) | ||
|
||
, redeemed_b2b_coupons as ( | ||
select b2bcoupon_id | ||
from allorders | ||
where | ||
redeemed = true | ||
and coupon_id is null | ||
group by b2bcoupon_id | ||
) | ||
|
||
select | ||
allcoupons.coupon_code | ||
, allcoupons.coupon_name | ||
, allcoupons.coupon_created_on | ||
, allcoupons.payment_transaction | ||
, allcoupons.discount_amount | ||
, allcoupons.coupon_type | ||
, allcoupons.discount_source | ||
, allcoupons.activated_on | ||
, allcoupons.expires_on | ||
, allcoupons.coupon_source_table | ||
, allcoupons.b2bcoupon_id | ||
, allcoupons.coupon_id | ||
, case | ||
when | ||
redeemed_coupons.coupon_id is not null | ||
or redeemed_b2b_coupons.b2bcoupon_id is not null | ||
then true | ||
when | ||
redeemed_coupons.coupon_id is null | ||
and redeemed_b2b_coupons.b2bcoupon_id is null | ||
then false | ||
end as redeemed | ||
from allcoupons | ||
left join redeemed_coupons | ||
on allcoupons.coupon_id = redeemed_coupons.coupon_id | ||
left join redeemed_b2b_coupons | ||
on allcoupons.b2bcoupon_id = redeemed_b2b_coupons.b2bcoupon_id |