query97.sql 927 B

12345678910111213141516171819202122
  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. group by ss_customer_sk ,ss_item_sk) ssci
  12. full outer join
  13. ( select cs_bill_customer_sk customer_sk
  14. ,cs_item_sk item_sk
  15. from catalog_sales
  16. JOIN date_dim ON catalog_sales.cs_sold_date_sk = date_dim.d_date_sk
  17. where
  18. d_month_seq between 1193 and 1193 + 11
  19. group by cs_bill_customer_sk ,cs_item_sk) csci
  20. on (ssci.customer_sk=csci.customer_sk and ssci.item_sk = csci.item_sk)
  21. limit 100;