1
0

query46.sql 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. select c_last_name
  2. ,c_first_name
  3. ,ca_city
  4. ,bought_city
  5. ,ss_ticket_number
  6. ,amt,profit
  7. from
  8. (select ss_ticket_number
  9. ,ss_customer_sk
  10. ,ca_city bought_city
  11. ,sum(ss_coupon_amt) amt
  12. ,sum(ss_net_profit) profit
  13. from store_sales,date_dim,store,household_demographics,customer_address
  14. where store_sales.ss_sold_date_sk = date_dim.d_date_sk
  15. and store_sales.ss_store_sk = store.s_store_sk
  16. and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
  17. and store_sales.ss_addr_sk = customer_address.ca_address_sk
  18. and (household_demographics.hd_dep_count = 4 or
  19. household_demographics.hd_vehicle_count= 2)
  20. and date_dim.d_dow in (6,0)
  21. and date_dim.d_year in (1998,1998+1,1998+2)
  22. and store.s_city in ('Rosedale','Bethlehem','Clinton','Clifton','Springfield')
  23. group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr
  24. where dn.ss_customer_sk = customer.c_customer_sk
  25. and customer.c_current_addr_sk = current_addr.ca_address_sk
  26. and current_addr.ca_city <> bought_city
  27. order by c_last_name
  28. ,c_first_name
  29. ,ca_city
  30. ,bought_city
  31. ,ss_ticket_number
  32. limit 100;