q16.sql 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. --!syntax_pg
  2. --TPC-DS Q16
  3. -- start query 1 in stream 0 using template ../query_templates/query16.tpl
  4. select
  5. count(distinct cs_order_number) as "order count"
  6. ,sum(cs_ext_ship_cost) as "total shipping cost"
  7. ,sum(cs_net_profit) as "total net profit"
  8. from
  9. plato.catalog_sales cs1
  10. ,plato.date_dim
  11. ,plato.customer_address
  12. ,plato.call_center
  13. where
  14. d_date between '1999-2-01'::date and
  15. (cast('1999-2-01' as date) + interval '60' day)::date
  16. and cs1.cs_ship_date_sk = d_date_sk
  17. and cs1.cs_ship_addr_sk = ca_address_sk
  18. and ca_state = 'IL'
  19. and cs1.cs_call_center_sk = cc_call_center_sk
  20. and cc_county in ('Williamson County','Williamson County','Williamson County','Williamson County',
  21. 'Williamson County'
  22. )
  23. and exists (select *
  24. from plato.catalog_sales cs2
  25. where cs1.cs_order_number = cs2.cs_order_number
  26. and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk)
  27. and not exists(select *
  28. from plato.catalog_returns cr1
  29. where cs1.cs_order_number = cr1.cr_order_number)
  30. order by count(distinct cs_order_number)
  31. limit 100;
  32. -- end query 1 in stream 0 using template ../query_templates/query16.tpl