Skip to content

Instantly share code, notes, and snippets.

@toddlipcon
Created January 30, 2019 20:24
Show Gist options
  • Save toddlipcon/b4b8c088cbd962cd7bd295674ffc9106 to your computer and use it in GitHub Desktop.
Save toddlipcon/b4b8c088cbd962cd7bd295674ffc9106 to your computer and use it in GitHub Desktop.
with dd as (
select d.d_date_sk
from date_dim d
where d.d_month_seq in (select distinct (d_month_seq) from date_dim where d_year = 2002 and d_moy = 1 )
)
select /* TPC-DS Q06 Original*/
a.ca_state state,
count(*) cnt
from
store_sales s ,
dd d ,
customer_address a ,
customer c ,
item i
where a.ca_address_sk = c.c_current_addr_sk
and c.c_customer_sk = s.ss_customer_sk
and s.ss_sold_date_sk = d.d_date_sk
and s.ss_item_sk = i.i_item_sk
and i.i_current_price > 1.2 * (select avg(j.i_current_price) from item j where j.i_category = i.i_category)
group by a.ca_state
having count(*) >= 10
order by cnt
limit 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment