query87.sql 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. select count(*)
  2. from (select distinct c_last_name as l1, c_first_name as f1, d_date as d1
  3. from store_sales
  4. JOIN date_dim ON store_sales.ss_sold_date_sk = date_dim.d_date_sk
  5. JOIN customer ON store_sales.ss_customer_sk = customer.c_customer_sk
  6. where
  7. d_month_seq between 1193 and 1193+11
  8. and ss_sold_date between '1999-06-01' and '2000-05-31'
  9. ) t1
  10. LEFT OUTER JOIN
  11. ( select distinct c_last_name as l2, c_first_name as f2, d_date as d2
  12. from catalog_sales
  13. JOIN date_dim ON catalog_sales.cs_sold_date_sk = date_dim.d_date_sk
  14. JOIN customer ON catalog_sales.cs_bill_customer_sk = customer.c_customer_sk
  15. where
  16. d_month_seq between 1193 and 1193+11
  17. and cs_sold_date between '1999-06-01' and '2000-05-31'
  18. ) t2
  19. ON t1.l1 = t2.l2 and
  20. t1.f1 = t2.f2 and
  21. t1.d1 = t2.d2
  22. LEFT OUTER JOIN
  23. (select distinct c_last_name as l3, c_first_name as f3, d_date as d3
  24. from web_sales
  25. JOIN date_dim ON web_sales.ws_sold_date_sk = date_dim.d_date_sk
  26. JOIN customer ON web_sales.ws_bill_customer_sk = customer.c_customer_sk
  27. where
  28. d_month_seq between 1193 and 1193+11
  29. and ws_sold_date between '1999-06-01' and '2000-05-31'
  30. ) t3
  31. ON t1.l1 = t3.l3 and
  32. t1.f1 = t3.f3 and
  33. t1.d1 = t3.d3
  34. WHERE
  35. l2 is null and
  36. l3 is null ;