q35.sql 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. SELECT
  2. ca_state,
  3. cd_gender,
  4. cd_marital_status,
  5. count(*) cnt1,
  6. min(cd_dep_count),
  7. max(cd_dep_count),
  8. avg(cd_dep_count),
  9. cd_dep_employed_count,
  10. count(*) cnt2,
  11. min(cd_dep_employed_count),
  12. max(cd_dep_employed_count),
  13. avg(cd_dep_employed_count),
  14. cd_dep_college_count,
  15. count(*) cnt3,
  16. min(cd_dep_college_count),
  17. max(cd_dep_college_count),
  18. avg(cd_dep_college_count)
  19. FROM
  20. customer c, customer_address ca, customer_demographics
  21. WHERE
  22. c.c_current_addr_sk = ca.ca_address_sk AND
  23. cd_demo_sk = c.c_current_cdemo_sk AND
  24. exists(SELECT *
  25. FROM store_sales, date_dim
  26. WHERE c.c_customer_sk = ss_customer_sk AND
  27. ss_sold_date_sk = d_date_sk AND
  28. d_year = 2002 AND
  29. d_qoy < 4) AND
  30. (exists(SELECT *
  31. FROM web_sales, date_dim
  32. WHERE c.c_customer_sk = ws_bill_customer_sk AND
  33. ws_sold_date_sk = d_date_sk AND
  34. d_year = 2002 AND
  35. d_qoy < 4) OR
  36. exists(SELECT *
  37. FROM catalog_sales, date_dim
  38. WHERE c.c_customer_sk = cs_ship_customer_sk AND
  39. cs_sold_date_sk = d_date_sk AND
  40. d_year = 2002 AND
  41. d_qoy < 4))
  42. GROUP BY ca_state, cd_gender, cd_marital_status, cd_dep_count,
  43. cd_dep_employed_count, cd_dep_college_count
  44. ORDER BY ca_state, cd_gender, cd_marital_status, cd_dep_count,
  45. cd_dep_employed_count, cd_dep_college_count
  46. LIMIT 100