Skip to content

Instantly share code, notes, and snippets.

@laurentedel
Created January 19, 2024 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laurentedel/0cba2094fc27278a0fc91850a57e2a35 to your computer and use it in GitHub Desktop.
Save laurentedel/0cba2094fc27278a0fc91850a57e2a35 to your computer and use it in GitHub Desktop.
query to explain
with
ctr_ttl_rtrn_tbl as (
select
sr_customer_sk as ctr_customer_sk,
sr_store_sk as ctr_store_sk,
sum(SR_FEE) as ctr_ttl_rtrn
from
store_returns,
date_dim
where
sr_returned_date_sk = d_date_sk
and d_year = 2000
group by
sr_customer_sk,
sr_store_sk
)
select
c_customer_id
from
ctr_ttl_rtrn_tbl ctr1,
store,
customer
where
ctr1.ctr_ttl_rtrn > (
select
avg(ctr_ttl_rtrn) * 1.2
from
ctr_ttl_rtrn_tbl ctr2
where
ctr1.ctr_store_sk = ctr2.ctr_store_sk
)
and s_store_sk = ctr1.ctr_store_sk
and s_state = 'NM'
and ctr1.ctr_customer_sk = c_customer_sk
order by
c_customer_id
limit
100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment