1
0

web_sales.sql 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_date_sk int,
  7. ws_sold_time_sk int,
  8. ws_ship_date_sk int,
  9. ws_item_sk int,
  10. ws_bill_customer_sk int,
  11. ws_bill_cdemo_sk int,
  12. ws_bill_hdemo_sk int,
  13. ws_bill_addr_sk int,
  14. ws_ship_customer_sk int,
  15. ws_ship_cdemo_sk int,
  16. ws_ship_hdemo_sk int,
  17. ws_ship_addr_sk int,
  18. ws_web_page_sk int,
  19. ws_web_site_sk int,
  20. ws_ship_mode_sk int,
  21. ws_warehouse_sk int,
  22. ws_promo_sk int,
  23. ws_order_number int,
  24. ws_quantity int,
  25. ws_wholesale_cost float,
  26. ws_list_price float,
  27. ws_sales_price float,
  28. ws_ext_discount_amt float,
  29. ws_ext_sales_price float,
  30. ws_ext_wholesale_cost float,
  31. ws_ext_list_price float,
  32. ws_ext_tax float,
  33. ws_coupon_amt float,
  34. ws_ext_ship_cost float,
  35. ws_net_paid float,
  36. ws_net_paid_inc_tax float,
  37. ws_net_paid_inc_ship float,
  38. ws_net_paid_inc_ship_tax float,
  39. ws_net_profit float
  40. )
  41. partitioned by (ws_sold_date string)
  42. stored as ${FILE};
  43. insert overwrite table web_sales partition (ws_sold_date)
  44. select
  45. ws.ws_sold_date_sk,
  46. ws.ws_sold_time_sk,
  47. ws.ws_ship_date_sk,
  48. ws.ws_item_sk,
  49. ws.ws_bill_customer_sk,
  50. ws.ws_bill_cdemo_sk,
  51. ws.ws_bill_hdemo_sk,
  52. ws.ws_bill_addr_sk,
  53. ws.ws_ship_customer_sk,
  54. ws.ws_ship_cdemo_sk,
  55. ws.ws_ship_hdemo_sk,
  56. ws.ws_ship_addr_sk,
  57. ws.ws_web_page_sk,
  58. ws.ws_web_site_sk,
  59. ws.ws_ship_mode_sk,
  60. ws.ws_warehouse_sk,
  61. ws.ws_promo_sk,
  62. ws.ws_order_number,
  63. ws.ws_quantity,
  64. ws.ws_wholesale_cost,
  65. ws.ws_list_price,
  66. ws.ws_sales_price,
  67. ws.ws_ext_discount_amt,
  68. ws.ws_ext_sales_price,
  69. ws.ws_ext_wholesale_cost,
  70. ws.ws_ext_list_price,
  71. ws.ws_ext_tax,
  72. ws.ws_coupon_amt,
  73. ws.ws_ext_ship_cost,
  74. ws.ws_net_paid,
  75. ws.ws_net_paid_inc_tax,
  76. ws.ws_net_paid_inc_ship,
  77. ws.ws_net_paid_inc_ship_tax,
  78. ws.ws_net_profit,
  79. dd.d_date as ws_sold_date
  80. from ${SOURCE}.web_sales ws
  81. join ${SOURCE}.date_dim dd
  82. on (ws.ws_sold_date_sk = dd.d_date_sk);