Skip to content

Commit

Permalink
add external files for queries to keep code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
csalvato committed Mar 7, 2016
1 parent f0f8f93 commit 5c52310
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
7 changes: 7 additions & 0 deletions adwords_campaigns_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"select
*
from
stage.gs_adwords_campaigns awc
where
awc.date between '@{start_date}' and '@{end_date}'
order by awc.date desc"
4 changes: 4 additions & 0 deletions influencer_metrics_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"select
*
from
fact_influencer_metrics fim"
64 changes: 64 additions & 0 deletions transactions_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"select
t.created_at as transaction_date
, du.name as user_name
, t.discount_amount
, ti.credit_used
, t.sales_tax_amount
, (CASE t.refunded
WHEN 't' THEN
ti.price
ELSE
0
END) as refund_amount
, (CASE
WHEN d.type = 'GiftCard'
THEN d.amount
ELSE
ti.price - t.sales_tax_amount + t.discount_amount
END) as retail_price
, (CASE t.refunded
WHEN 't' THEN
0
ELSE
ti.price - ti.credit_used
END) as money_in_the_bank_paid_to_us
, (CASE
WHEN d.type = 'GiftCard'
THEN 'Gift Card'
WHEN ti.recurring = 't'
THEN 'Recurring Food Purchase'
ELSE
'One-Time Meal Purchase'
END
) as purchase_type
--, ti.name as meal_plan
--, ti.recurring
-- , l.name
-- , l.city
-- , l.state
-- , l.store_front_id
-- , l.home_delivery
, mp.*
from
transactions t
inner join
transaction_items ti on t.id = ti.transaction_id
inner join
dim_users du on t.user_id = du.user_id
inner join
(
select distinct on (gsm.user_id)
gsm.*
from
stage.gs_mixpanel gsm
order by gsm.user_id, mixpanel_event_timestamp
) mp on du.user_id = mp.user_id
--left outer join
-- locations l on ti.location_id = l.id
left outer join
discounts d on ti.discount_id = d.id
where
t.created_at between '@{start_date}' and '@{end_date}'
-- AND
-- t.refunded IS NOT TRUE
order by t.created_at desc"

0 comments on commit 5c52310

Please sign in to comment.