query34.sql 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. select c_last_name
  2. ,c_first_name
  3. ,c_salutation
  4. ,c_preferred_cust_flag
  5. ,ss_ticket_number
  6. ,cnt from
  7. (select ss_ticket_number
  8. ,ss_customer_sk
  9. ,count(*) cnt
  10. from store_sales,date_dim,store,household_demographics
  11. where store_sales.ss_sold_date_sk = date_dim.d_date_sk
  12. and store_sales.ss_store_sk = store.s_store_sk
  13. and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
  14. and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28)
  15. and (household_demographics.hd_buy_potential = '1001-5000' or
  16. household_demographics.hd_buy_potential = '5001-10000')
  17. and household_demographics.hd_vehicle_count > 0
  18. and (case when household_demographics.hd_vehicle_count > 0
  19. then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count
  20. else null
  21. end) > 1.2
  22. and date_dim.d_year in (1998,1998+1,1998+2)
  23. and (
  24. ss_sold_date in (
  25. '1998-01-01', '1998-01-02', '1998-01-03', '1998-01-25', '1998-01-26', '1998-01-27',
  26. '1998-01-28', '1998-02-01', '1998-02-02', '1998-02-03', '1998-02-25', '1998-02-26',
  27. '1998-02-27', '1998-02-28', '1998-03-01', '1998-03-02', '1998-03-03', '1998-03-25',
  28. '1998-03-26', '1998-03-27', '1998-03-28', '1998-04-01', '1998-04-02', '1998-04-03',
  29. '1998-04-25', '1998-04-26', '1998-04-27', '1998-04-28', '1998-05-01', '1998-05-02',
  30. '1998-05-03', '1998-05-25', '1998-05-26', '1998-05-27', '1998-05-28', '1998-06-01',
  31. '1998-06-02', '1998-06-03', '1998-06-25', '1998-06-26', '1998-06-27', '1998-06-28',
  32. '1998-07-01', '1998-07-02', '1998-07-03', '1998-07-25', '1998-07-26', '1998-07-27',
  33. '1998-07-28', '1998-08-01', '1998-08-02', '1998-08-03', '1998-08-25', '1998-08-26',
  34. '1998-08-27', '1998-08-28', '1998-09-01', '1998-09-02', '1998-09-03', '1998-09-25',
  35. '1998-09-26', '1998-09-27', '1998-09-28', '1998-10-01', '1998-10-02', '1998-10-03',
  36. '1998-10-25', '1998-10-26', '1998-10-27', '1998-10-28', '1998-11-01', '1998-11-02',
  37. '1998-11-03', '1998-11-25', '1998-11-26', '1998-11-27', '1998-11-28', '1998-12-01',
  38. '1998-12-02', '1998-12-03', '1998-12-25', '1998-12-26', '1998-12-27', '1998-12-28',
  39. '1999-01-01', '1999-01-02', '1999-01-03', '1999-01-25', '1999-01-26', '1999-01-27',
  40. '1999-01-28', '1999-02-01', '1999-02-02', '1999-02-03', '1999-02-25', '1999-02-26',
  41. '1999-02-27', '1999-02-28', '1999-03-01', '1999-03-02', '1999-03-03', '1999-03-25',
  42. '1999-03-26', '1999-03-27', '1999-03-28', '1999-04-01', '1999-04-02', '1999-04-03',
  43. '1999-04-25', '1999-04-26', '1999-04-27', '1999-04-28', '1999-05-01', '1999-05-02',
  44. '1999-05-03', '1999-05-25', '1999-05-26', '1999-05-27', '1999-05-28', '1999-06-01',
  45. '1999-06-02', '1999-06-03', '1999-06-25', '1999-06-26', '1999-06-27', '1999-06-28',
  46. '1999-07-01', '1999-07-02', '1999-07-03', '1999-07-25', '1999-07-26', '1999-07-27',
  47. '1999-07-28', '1999-08-01', '1999-08-02', '1999-08-03', '1999-08-25', '1999-08-26',
  48. '1999-08-27', '1999-08-28', '1999-09-01', '1999-09-02', '1999-09-03', '1999-09-25',
  49. '1999-09-26', '1999-09-27', '1999-09-28', '1999-10-01', '1999-10-02', '1999-10-03',
  50. '1999-10-25', '1999-10-26', '1999-10-27', '1999-10-28', '1999-11-01', '1999-11-02',
  51. '1999-11-03', '1999-11-25', '1999-11-26', '1999-11-27', '1999-11-28', '1999-12-01',
  52. '1999-12-02', '1999-12-03', '1999-12-25', '1999-12-26', '1999-12-27', '1999-12-28',
  53. '2000-01-01', '2000-01-02', '2000-01-03', '2000-01-25', '2000-01-26', '2000-01-27',
  54. '2000-01-28', '2000-02-01', '2000-02-02', '2000-02-03', '2000-02-25', '2000-02-26',
  55. '2000-02-27', '2000-02-28', '2000-03-01', '2000-03-02', '2000-03-03', '2000-03-25',
  56. '2000-03-26', '2000-03-27', '2000-03-28', '2000-04-01', '2000-04-02', '2000-04-03',
  57. '2000-04-25', '2000-04-26', '2000-04-27', '2000-04-28', '2000-05-01', '2000-05-02',
  58. '2000-05-03', '2000-05-25', '2000-05-26', '2000-05-27', '2000-05-28', '2000-06-01',
  59. '2000-06-02', '2000-06-03', '2000-06-25', '2000-06-26', '2000-06-27', '2000-06-28',
  60. '2000-07-01', '2000-07-02', '2000-07-03', '2000-07-25', '2000-07-26', '2000-07-27',
  61. '2000-07-28', '2000-08-01', '2000-08-02', '2000-08-03', '2000-08-25', '2000-08-26',
  62. '2000-08-27', '2000-08-28', '2000-09-01', '2000-09-02', '2000-09-03', '2000-09-25',
  63. '2000-09-26', '2000-09-27', '2000-09-28', '2000-10-01', '2000-10-02', '2000-10-03',
  64. '2000-10-25', '2000-10-26', '2000-10-27', '2000-10-28', '2000-11-01', '2000-11-02',
  65. '2000-11-03', '2000-11-25', '2000-11-26', '2000-11-27', '2000-11-28', '2000-12-01',
  66. '2000-12-02', '2000-12-03', '2000-12-25', '2000-12-26', '2000-12-27', '2000-12-28'
  67. )
  68. )
  69. and store.s_county in ('Kittitas County','Adams County','Richland County','Furnas County',
  70. 'Orange County','Appanoose County','Franklin Parish','Tehama County')
  71. group by ss_ticket_number,ss_customer_sk) dn,customer
  72. where dn.ss_customer_sk = customer.c_customer_sk
  73. and cnt between 15 and 20
  74. order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc;