query13.sql 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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((store_sales.ss_hdemo_sk=household_demographics.hd_demo_sk
  14. and customer_demographics.cd_demo_sk = store_sales.ss_cdemo_sk
  15. and customer_demographics.cd_marital_status = 'M'
  16. and customer_demographics.cd_education_status = '4 yr Degree'
  17. and store_sales.ss_sales_price between 100.00 and 150.00
  18. and household_demographics.hd_dep_count = 3
  19. )or
  20. (store_sales.ss_hdemo_sk=household_demographics.hd_demo_sk
  21. and customer_demographics.cd_demo_sk = store_sales.ss_cdemo_sk
  22. and customer_demographics.cd_marital_status = 'D'
  23. and customer_demographics.cd_education_status = 'Primary'
  24. and store_sales.ss_sales_price between 50.00 and 100.00
  25. and household_demographics.hd_dep_count = 1
  26. ) or
  27. (store_sales.ss_hdemo_sk=household_demographics.hd_demo_sk
  28. and customer_demographics.cd_demo_sk = ss_cdemo_sk
  29. and customer_demographics.cd_marital_status = 'U'
  30. and customer_demographics.cd_education_status = 'Advanced Degree'
  31. and store_sales.ss_sales_price between 150.00 and 200.00
  32. and household_demographics.hd_dep_count = 1
  33. ))
  34. and((store_sales.ss_addr_sk = customer_address.ca_address_sk
  35. and customer_address.ca_country = 'United States'
  36. and customer_address.ca_state in ('KY', 'GA', 'NM')
  37. and store_sales.ss_net_profit between 100 and 200
  38. ) or
  39. (store_sales.ss_addr_sk = customer_address.ca_address_sk
  40. and customer_address.ca_country = 'United States'
  41. and customer_address.ca_state in ('MT', 'OR', 'IN')
  42. and store_sales.ss_net_profit between 150 and 300
  43. ) or
  44. (store_sales.ss_addr_sk = customer_address.ca_address_sk
  45. and customer_address.ca_country = 'United States'
  46. and customer_address.ca_state in ('WI', 'MO', 'WV')
  47. and store_sales.ss_net_profit between 50 and 250
  48. ))
  49. ;