q34.sql 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. --!syntax_pg
  2. --TPC-DS Q34
  3. -- start query 1 in stream 0 using template ../query_templates/query34.tpl
  4. select c_last_name
  5. ,c_first_name
  6. ,c_salutation
  7. ,c_preferred_cust_flag
  8. ,ss_ticket_number
  9. ,cnt from
  10. (select ss_ticket_number
  11. ,ss_customer_sk
  12. ,count(*) cnt
  13. from plato.store_sales,plato.date_dim,plato.store,plato.household_demographics
  14. where store_sales.ss_sold_date_sk = date_dim.d_date_sk
  15. and store_sales.ss_store_sk = store.s_store_sk
  16. and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
  17. and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28)
  18. and (household_demographics.hd_buy_potential = '>10000' or
  19. household_demographics.hd_buy_potential = 'Unknown')
  20. and household_demographics.hd_vehicle_count > 0
  21. and (case when household_demographics.hd_vehicle_count > 0
  22. then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count
  23. else null::int4
  24. end)::float8 > 1.2::float8
  25. and date_dim.d_year in (1998,1998+1,1998+2)
  26. and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County',
  27. 'Williamson County','Williamson County','Williamson County','Williamson County')
  28. group by ss_ticket_number,ss_customer_sk) dn,plato.customer
  29. where ss_customer_sk = c_customer_sk
  30. and cnt between 15::int8 and 20::int8
  31. order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number;
  32. -- end query 1 in stream 0 using template ../query_templates/query34.tpl