query16.sql 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. -- start query 1 in stream 0 using template query16.tpl and seed 171719422
  2. select
  3. count(distinct cs_order_number) as `order count`
  4. ,sum(cs_ext_ship_cost) as `total shipping cost`
  5. ,sum(cs_net_profit) as `total net profit`
  6. from
  7. catalog_sales cs1
  8. ,date_dim
  9. ,customer_address
  10. ,call_center
  11. where
  12. d_date between '2001-4-01' and
  13. (cast('2001-4-01' as date) + interval '60' days)
  14. and cs1.cs_ship_date_sk = d_date_sk
  15. and cs1.cs_ship_addr_sk = ca_address_sk
  16. and ca_state = 'NY'
  17. and cs1.cs_call_center_sk = cc_call_center_sk
  18. and cc_county in ('Ziebach County','Levy County','Huron County','Franklin Parish',
  19. 'Daviess County'
  20. )
  21. and exists (select *
  22. from catalog_sales cs2
  23. where cs1.cs_order_number = cs2.cs_order_number
  24. and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk)
  25. and not exists(select *
  26. from catalog_returns cr1
  27. where cs1.cs_order_number = cr1.cr_order_number)
  28. order by `order count`
  29. limit 100;
  30. -- end query 1 in stream 0 using template query16.tpl