q30.sql 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. --!syntax_pg
  2. --TPC-DS Q30
  3. -- start query 1 in stream 0 using template ../query_templates/query30.tpl
  4. with customer_total_return as
  5. (select wr_returning_customer_sk as ctr_customer_sk
  6. ,ca_state as ctr_state,
  7. sum(wr_return_amt) as ctr_total_return
  8. from plato.web_returns
  9. ,plato.date_dim
  10. ,plato.customer_address
  11. where wr_returned_date_sk = d_date_sk
  12. and d_year =2002
  13. and wr_returning_addr_sk = ca_address_sk
  14. group by wr_returning_customer_sk
  15. ,ca_state)
  16. select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag
  17. ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address
  18. ,c_last_review_date,ctr_total_return
  19. from customer_total_return ctr1
  20. ,plato.customer_address
  21. ,plato.customer
  22. where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2::numeric
  23. from customer_total_return ctr2
  24. where ctr1.ctr_state = ctr2.ctr_state)
  25. and ca_address_sk = c_current_addr_sk
  26. and ca_state = 'IL'
  27. and ctr1.ctr_customer_sk = c_customer_sk
  28. order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag
  29. ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address
  30. ,c_last_review_date,ctr_total_return
  31. limit 100;
  32. -- end query 1 in stream 0 using template ../query_templates/query30.tpl