query31.sql 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- start query 1 in stream 0 using template query31.tpl and seed 1819994127
  2. with ss as
  3. (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales
  4. from store_sales,date_dim,customer_address
  5. where ss_sold_date_sk = d_date_sk
  6. and ss_addr_sk=ca_address_sk
  7. group by ca_county,d_qoy, d_year),
  8. ws as
  9. (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales
  10. from web_sales,date_dim,customer_address
  11. where ws_sold_date_sk = d_date_sk
  12. and ws_bill_addr_sk=ca_address_sk
  13. group by ca_county,d_qoy, d_year)
  14. select
  15. ss1.ca_county
  16. ,ss1.d_year
  17. ,ws2.web_sales/ws1.web_sales web_q1_q2_increase
  18. ,ss2.store_sales/ss1.store_sales store_q1_q2_increase
  19. ,ws3.web_sales/ws2.web_sales web_q2_q3_increase
  20. ,ss3.store_sales/ss2.store_sales store_q2_q3_increase
  21. from
  22. ss ss1
  23. ,ss ss2
  24. ,ss ss3
  25. ,ws ws1
  26. ,ws ws2
  27. ,ws ws3
  28. where
  29. ss1.d_qoy = 1
  30. and ss1.d_year = 1999
  31. and ss1.ca_county = ss2.ca_county
  32. and ss2.d_qoy = 2
  33. and ss2.d_year = 1999
  34. and ss2.ca_county = ss3.ca_county
  35. and ss3.d_qoy = 3
  36. and ss3.d_year = 1999
  37. and ss1.ca_county = ws1.ca_county
  38. and ws1.d_qoy = 1
  39. and ws1.d_year = 1999
  40. and ws1.ca_county = ws2.ca_county
  41. and ws2.d_qoy = 2
  42. and ws2.d_year = 1999
  43. and ws1.ca_county = ws3.ca_county
  44. and ws3.d_qoy = 3
  45. and ws3.d_year =1999
  46. and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end
  47. > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end
  48. and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end
  49. > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end
  50. order by ss1.d_year;
  51. -- end query 1 in stream 0 using template query31.tpl