1
0

web_sales.sql 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. create database if not exists ${DB};
  2. use ${DB};
  3. drop table if exists web_sales;
  4. create table web_sales
  5. (
  6. ws_sold_time_sk bigint,
  7. ws_ship_date_sk bigint,
  8. ws_item_sk bigint,
  9. ws_bill_customer_sk bigint,
  10. ws_bill_cdemo_sk bigint,
  11. ws_bill_hdemo_sk bigint,
  12. ws_bill_addr_sk bigint,
  13. ws_ship_customer_sk bigint,
  14. ws_ship_cdemo_sk bigint,
  15. ws_ship_hdemo_sk bigint,
  16. ws_ship_addr_sk bigint,
  17. ws_web_page_sk bigint,
  18. ws_web_site_sk bigint,
  19. ws_ship_mode_sk bigint,
  20. ws_warehouse_sk bigint,
  21. ws_promo_sk bigint,
  22. ws_order_number bigint,
  23. ws_quantity int,
  24. ws_wholesale_cost double,
  25. ws_list_price double,
  26. ws_sales_price double,
  27. ws_ext_discount_amt double,
  28. ws_ext_sales_price double,
  29. ws_ext_wholesale_cost double,
  30. ws_ext_list_price double,
  31. ws_ext_tax double,
  32. ws_coupon_amt double,
  33. ws_ext_ship_cost double,
  34. ws_net_paid double,
  35. ws_net_paid_inc_tax double,
  36. ws_net_paid_inc_ship double,
  37. ws_net_paid_inc_ship_tax double,
  38. ws_net_profit double
  39. )
  40. partitioned by (ws_sold_date_sk bigint)
  41. stored as ${FILE};
  42. from ${SOURCE}.web_sales ws
  43. insert overwrite table web_sales partition (ws_sold_date_sk)
  44. select
  45. ws.ws_sold_time_sk,
  46. ws.ws_ship_date_sk,
  47. ws.ws_item_sk,
  48. ws.ws_bill_customer_sk,
  49. ws.ws_bill_cdemo_sk,
  50. ws.ws_bill_hdemo_sk,
  51. ws.ws_bill_addr_sk,
  52. ws.ws_ship_customer_sk,
  53. ws.ws_ship_cdemo_sk,
  54. ws.ws_ship_hdemo_sk,
  55. ws.ws_ship_addr_sk,
  56. ws.ws_web_page_sk,
  57. ws.ws_web_site_sk,
  58. ws.ws_ship_mode_sk,
  59. ws.ws_warehouse_sk,
  60. ws.ws_promo_sk,
  61. ws.ws_order_number,
  62. ws.ws_quantity,
  63. ws.ws_wholesale_cost,
  64. ws.ws_list_price,
  65. ws.ws_sales_price,
  66. ws.ws_ext_discount_amt,
  67. ws.ws_ext_sales_price,
  68. ws.ws_ext_wholesale_cost,
  69. ws.ws_ext_list_price,
  70. ws.ws_ext_tax,
  71. ws.ws_coupon_amt,
  72. ws.ws_ext_ship_cost,
  73. ws.ws_net_paid,
  74. ws.ws_net_paid_inc_tax,
  75. ws.ws_net_paid_inc_ship,
  76. ws.ws_net_paid_inc_ship_tax,
  77. ws.ws_net_profit,
  78. ws.ws_sold_date_sk
  79. where ws.ws_sold_date_sk is not null
  80. insert overwrite table web_sales partition (ws_sold_date_sk)
  81. select
  82. ws.ws_sold_time_sk,
  83. ws.ws_ship_date_sk,
  84. ws.ws_item_sk,
  85. ws.ws_bill_customer_sk,
  86. ws.ws_bill_cdemo_sk,
  87. ws.ws_bill_hdemo_sk,
  88. ws.ws_bill_addr_sk,
  89. ws.ws_ship_customer_sk,
  90. ws.ws_ship_cdemo_sk,
  91. ws.ws_ship_hdemo_sk,
  92. ws.ws_ship_addr_sk,
  93. ws.ws_web_page_sk,
  94. ws.ws_web_site_sk,
  95. ws.ws_ship_mode_sk,
  96. ws.ws_warehouse_sk,
  97. ws.ws_promo_sk,
  98. ws.ws_order_number,
  99. ws.ws_quantity,
  100. ws.ws_wholesale_cost,
  101. ws.ws_list_price,
  102. ws.ws_sales_price,
  103. ws.ws_ext_discount_amt,
  104. ws.ws_ext_sales_price,
  105. ws.ws_ext_wholesale_cost,
  106. ws.ws_ext_list_price,
  107. ws.ws_ext_tax,
  108. ws.ws_coupon_amt,
  109. ws.ws_ext_ship_cost,
  110. ws.ws_net_paid,
  111. ws.ws_net_paid_inc_tax,
  112. ws.ws_net_paid_inc_ship,
  113. ws.ws_net_paid_inc_ship_tax,
  114. ws.ws_net_profit,
  115. ws.ws_sold_date_sk
  116. where ws.ws_sold_date_sk is null
  117. sort by ws.ws_sold_date_sk
  118. ;