q73.sql 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. --!syntax_pg
  2. --TPC-DS Q73
  3. -- start query 1 in stream 0 using template ../query_templates/query73.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 2
  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 then
  22. household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null::int4 end > 1
  23. and date_dim.d_year in (1998,1998+1,1998+2)
  24. and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County')
  25. group by ss_ticket_number,ss_customer_sk) dj,plato.customer
  26. where ss_customer_sk = c_customer_sk
  27. and cnt between 1::int8 and 5::int8
  28. order by cnt desc, c_last_name asc;
  29. -- end query 1 in stream 0 using template ../query_templates/query73.tpl