query87.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. ) t1
  9. LEFT OUTER JOIN
  10. ( select distinct c_last_name as l2, c_first_name as f2, d_date as d2
  11. from catalog_sales
  12. JOIN date_dim ON catalog_sales.cs_sold_date_sk = date_dim.d_date_sk
  13. JOIN customer ON catalog_sales.cs_bill_customer_sk = customer.c_customer_sk
  14. where
  15. d_month_seq between 1193 and 1193+11
  16. ) t2
  17. ON t1.l1 = t2.l2 and
  18. t1.f1 = t2.f2 and
  19. t1.d1 = t2.d2
  20. LEFT OUTER JOIN
  21. (select distinct c_last_name as l3, c_first_name as f3, d_date as d3
  22. from web_sales
  23. JOIN date_dim ON web_sales.ws_sold_date_sk = date_dim.d_date_sk
  24. JOIN customer ON web_sales.ws_bill_customer_sk = customer.c_customer_sk
  25. where
  26. d_month_seq between 1193 and 1193+11
  27. ) t3
  28. ON t1.l1 = t3.l3 and
  29. t1.f1 = t3.f3 and
  30. t1.d1 = t3.d3
  31. WHERE
  32. l2 is null and
  33. l3 is null ;