1
0

query81.sql 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. -- start query 1 in stream 0 using template query81.tpl and seed 1819994127
  2. with customer_total_return as
  3. (select cr_returning_customer_sk as ctr_customer_sk
  4. ,ca_state as ctr_state,
  5. sum(cr_return_amt_inc_tax) as ctr_total_return
  6. from catalog_returns
  7. ,date_dim
  8. ,customer_address
  9. where cr_returned_date_sk = d_date_sk
  10. and d_year =1998
  11. and cr_returning_addr_sk = ca_address_sk
  12. group by cr_returning_customer_sk
  13. ,ca_state )
  14. select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name
  15. ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset
  16. ,ca_location_type,ctr_total_return
  17. from customer_total_return ctr1
  18. ,customer_address
  19. ,customer
  20. where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2
  21. from customer_total_return ctr2
  22. where ctr1.ctr_state = ctr2.ctr_state)
  23. and ca_address_sk = c_current_addr_sk
  24. and ca_state = 'TX'
  25. and ctr1.ctr_customer_sk = c_customer_sk
  26. order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name
  27. ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset
  28. ,ca_location_type,ctr_total_return
  29. limit 100;
  30. -- end query 1 in stream 0 using template query81.tpl