query46.sql 1.4 KB

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