query13.sql 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. select avg(ss_quantity)
  2. ,avg(ss_ext_sales_price)
  3. ,avg(ss_ext_wholesale_cost)
  4. ,sum(ss_ext_wholesale_cost)
  5. from store_sales
  6. ,store
  7. ,customer_demographics
  8. ,household_demographics
  9. ,customer_address
  10. ,date_dim
  11. where store.s_store_sk = store_sales.ss_store_sk
  12. and store_sales.ss_sold_date_sk = date_dim.d_date_sk and date_dim.d_year = 2001
  13. and ss_sold_date between '2001-01-01' and '2001-12-31'
  14. and((store_sales.ss_hdemo_sk=household_demographics.hd_demo_sk
  15. and customer_demographics.cd_demo_sk = store_sales.ss_cdemo_sk
  16. and customer_demographics.cd_marital_status = 'M'
  17. and customer_demographics.cd_education_status = '4 yr Degree'
  18. and store_sales.ss_sales_price between 100.00 and 150.00
  19. and household_demographics.hd_dep_count = 3
  20. )or
  21. (store_sales.ss_hdemo_sk=household_demographics.hd_demo_sk
  22. and customer_demographics.cd_demo_sk = store_sales.ss_cdemo_sk
  23. and customer_demographics.cd_marital_status = 'D'
  24. and customer_demographics.cd_education_status = 'Primary'
  25. and store_sales.ss_sales_price between 50.00 and 100.00
  26. and household_demographics.hd_dep_count = 1
  27. ) or
  28. (store_sales.ss_hdemo_sk=household_demographics.hd_demo_sk
  29. and customer_demographics.cd_demo_sk = ss_cdemo_sk
  30. and customer_demographics.cd_marital_status = 'U'
  31. and customer_demographics.cd_education_status = 'Advanced Degree'
  32. and store_sales.ss_sales_price between 150.00 and 200.00
  33. and household_demographics.hd_dep_count = 1
  34. ))
  35. and((store_sales.ss_addr_sk = customer_address.ca_address_sk
  36. and customer_address.ca_country = 'United States'
  37. and customer_address.ca_state in ('KY', 'GA', 'NM')
  38. and store_sales.ss_net_profit between 100 and 200
  39. ) or
  40. (store_sales.ss_addr_sk = customer_address.ca_address_sk
  41. and customer_address.ca_country = 'United States'
  42. and customer_address.ca_state in ('MT', 'OR', 'IN')
  43. and store_sales.ss_net_profit between 150 and 300
  44. ) or
  45. (store_sales.ss_addr_sk = customer_address.ca_address_sk
  46. and customer_address.ca_country = 'United States'
  47. and customer_address.ca_state in ('WI', 'MO', 'WV')
  48. and store_sales.ss_net_profit between 50 and 250
  49. ))
  50. ;