query97.sql 1.0 KB

123456789101112131415161718192021222324
  1. select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only
  2. ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only
  3. ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog
  4. from
  5. ( select ss_customer_sk customer_sk
  6. ,ss_item_sk item_sk
  7. from store_sales
  8. JOIN date_dim ON store_sales.ss_sold_date_sk = date_dim.d_date_sk
  9. where
  10. d_month_seq between 1193 and 1193 + 11
  11. and ss_sold_date between '1999-06-01' and '2000-05-31'
  12. group by ss_customer_sk ,ss_item_sk) ssci
  13. full outer join
  14. ( select cs_bill_customer_sk customer_sk
  15. ,cs_item_sk item_sk
  16. from catalog_sales
  17. JOIN date_dim ON catalog_sales.cs_sold_date_sk = date_dim.d_date_sk
  18. where
  19. d_month_seq between 1193 and 1193 + 11
  20. and cs_sold_date between '1999-06-01' and '2000-05-31'
  21. group by cs_bill_customer_sk ,cs_item_sk) csci
  22. on (ssci.customer_sk=csci.customer_sk and ssci.item_sk = csci.item_sk)
  23. limit 100;