q46.sql 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. --!syntax_pg
  2. --TPC-DS Q46
  3. -- start query 1 in stream 0 using template ../query_templates/query46.tpl
  4. select c_last_name
  5. ,c_first_name
  6. ,ca_city
  7. ,bought_city
  8. ,ss_ticket_number
  9. ,amt,profit
  10. from
  11. (select ss_ticket_number
  12. ,ss_customer_sk
  13. ,ca_city bought_city
  14. ,sum(ss_coupon_amt) amt
  15. ,sum(ss_net_profit) profit
  16. from plato.store_sales,plato.date_dim,plato.store,plato.household_demographics,plato.customer_address
  17. where store_sales.ss_sold_date_sk = date_dim.d_date_sk
  18. and store_sales.ss_store_sk = store.s_store_sk
  19. and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
  20. and store_sales.ss_addr_sk = customer_address.ca_address_sk
  21. and (household_demographics.hd_dep_count = 5 or
  22. household_demographics.hd_vehicle_count= 3)
  23. and date_dim.d_dow in (6,0)
  24. and date_dim.d_year in (1999,1999+1,1999+2)
  25. and store.s_city in ('Midway','Fairview','Fairview','Midway','Fairview')
  26. group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,plato.customer,plato.customer_address current_addr
  27. where ss_customer_sk = c_customer_sk
  28. and customer.c_current_addr_sk = current_addr.ca_address_sk
  29. and current_addr.ca_city <> bought_city
  30. order by c_last_name
  31. ,c_first_name
  32. ,ca_city
  33. ,bought_city
  34. ,ss_ticket_number
  35. limit 100;
  36. -- end query 1 in stream 0 using template ../query_templates/query46.tpl