1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
--!syntax_pg
--TPC-DS Q66
-- start query 1 in stream 0 using template ../query_templates/query66.tpl
select
w_warehouse_name
,w_warehouse_sq_ft
,w_city
,w_county
,w_state
,w_country
,ship_carriers
,year
,sum(jan_sales) as jan_sales
,sum(feb_sales) as feb_sales
,sum(mar_sales) as mar_sales
,sum(apr_sales) as apr_sales
,sum(may_sales) as may_sales
,sum(jun_sales) as jun_sales
,sum(jul_sales) as jul_sales
,sum(aug_sales) as aug_sales
,sum(sep_sales) as sep_sales
,sum(oct_sales) as oct_sales
,sum(nov_sales) as nov_sales
,sum(dec_sales) as dec_sales
,sum(jan_sales/w_warehouse_sq_ft::numeric) as jan_sales_per_sq_foot
,sum(feb_sales/w_warehouse_sq_ft::numeric) as feb_sales_per_sq_foot
,sum(mar_sales/w_warehouse_sq_ft::numeric) as mar_sales_per_sq_foot
,sum(apr_sales/w_warehouse_sq_ft::numeric) as apr_sales_per_sq_foot
,sum(may_sales/w_warehouse_sq_ft::numeric) as may_sales_per_sq_foot
,sum(jun_sales/w_warehouse_sq_ft::numeric) as jun_sales_per_sq_foot
,sum(jul_sales/w_warehouse_sq_ft::numeric) as jul_sales_per_sq_foot
,sum(aug_sales/w_warehouse_sq_ft::numeric) as aug_sales_per_sq_foot
,sum(sep_sales/w_warehouse_sq_ft::numeric) as sep_sales_per_sq_foot
,sum(oct_sales/w_warehouse_sq_ft::numeric) as oct_sales_per_sq_foot
,sum(nov_sales/w_warehouse_sq_ft::numeric) as nov_sales_per_sq_foot
,sum(dec_sales/w_warehouse_sq_ft::numeric) as dec_sales_per_sq_foot
,sum(jan_net) as jan_net
,sum(feb_net) as feb_net
,sum(mar_net) as mar_net
,sum(apr_net) as apr_net
,sum(may_net) as may_net
,sum(jun_net) as jun_net
,sum(jul_net) as jul_net
,sum(aug_net) as aug_net
,sum(sep_net) as sep_net
,sum(oct_net) as oct_net
,sum(nov_net) as nov_net
,sum(dec_net) as dec_net
from (
select
w_warehouse_name
,w_warehouse_sq_ft
,w_city
,w_county
,w_state
,w_country
,'DIAMOND' || ',' || 'AIRBORNE' as ship_carriers
,d_year as year
,sum(case when d_moy = 1
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as jan_sales
,sum(case when d_moy = 2
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as feb_sales
,sum(case when d_moy = 3
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as mar_sales
,sum(case when d_moy = 4
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as apr_sales
,sum(case when d_moy = 5
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as may_sales
,sum(case when d_moy = 6
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as jun_sales
,sum(case when d_moy = 7
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as jul_sales
,sum(case when d_moy = 8
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as aug_sales
,sum(case when d_moy = 9
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as sep_sales
,sum(case when d_moy = 10
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as oct_sales
,sum(case when d_moy = 11
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as nov_sales
,sum(case when d_moy = 12
then ws_sales_price* ws_quantity::numeric else 0::numeric end) as dec_sales
,sum(case when d_moy = 1
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as jan_net
,sum(case when d_moy = 2
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as feb_net
,sum(case when d_moy = 3
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as mar_net
,sum(case when d_moy = 4
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as apr_net
,sum(case when d_moy = 5
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as may_net
,sum(case when d_moy = 6
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as jun_net
,sum(case when d_moy = 7
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as jul_net
,sum(case when d_moy = 8
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as aug_net
,sum(case when d_moy = 9
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as sep_net
,sum(case when d_moy = 10
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as oct_net
,sum(case when d_moy = 11
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as nov_net
,sum(case when d_moy = 12
then ws_net_paid_inc_tax * ws_quantity::numeric else 0::numeric end) as dec_net
from
plato.web_sales
,plato.warehouse
,plato.date_dim
,plato.time_dim
,plato.ship_mode
where
ws_warehouse_sk = w_warehouse_sk
and ws_sold_date_sk = d_date_sk
and ws_sold_time_sk = t_time_sk
and ws_ship_mode_sk = sm_ship_mode_sk
and d_year = 2002
and t_time between 49530 and 49530+28800
and sm_carrier in ('DIAMOND','AIRBORNE')
group by
w_warehouse_name
,w_warehouse_sq_ft
,w_city
,w_county
,w_state
,w_country
,d_year
union all
select
w_warehouse_name
,w_warehouse_sq_ft
,w_city
,w_county
,w_state
,w_country
,'DIAMOND' || ',' || 'AIRBORNE' as ship_carriers
,d_year as year
,sum(case when d_moy = 1
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as jan_sales
,sum(case when d_moy = 2
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as feb_sales
,sum(case when d_moy = 3
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as mar_sales
,sum(case when d_moy = 4
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as apr_sales
,sum(case when d_moy = 5
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as may_sales
,sum(case when d_moy = 6
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as jun_sales
,sum(case when d_moy = 7
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as jul_sales
,sum(case when d_moy = 8
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as aug_sales
,sum(case when d_moy = 9
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as sep_sales
,sum(case when d_moy = 10
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as oct_sales
,sum(case when d_moy = 11
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as nov_sales
,sum(case when d_moy = 12
then cs_ext_sales_price* cs_quantity::numeric else 0::numeric end) as dec_sales
,sum(case when d_moy = 1
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as jan_net
,sum(case when d_moy = 2
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as feb_net
,sum(case when d_moy = 3
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as mar_net
,sum(case when d_moy = 4
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as apr_net
,sum(case when d_moy = 5
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as may_net
,sum(case when d_moy = 6
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as jun_net
,sum(case when d_moy = 7
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as jul_net
,sum(case when d_moy = 8
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as aug_net
,sum(case when d_moy = 9
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as sep_net
,sum(case when d_moy = 10
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as oct_net
,sum(case when d_moy = 11
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as nov_net
,sum(case when d_moy = 12
then cs_net_paid_inc_ship_tax * cs_quantity::numeric else 0::numeric end) as dec_net
from
plato.catalog_sales
,plato.warehouse
,plato.date_dim
,plato.time_dim
,plato.ship_mode
where
cs_warehouse_sk = w_warehouse_sk
and cs_sold_date_sk = d_date_sk
and cs_sold_time_sk = t_time_sk
and cs_ship_mode_sk = sm_ship_mode_sk
and d_year = 2002
and t_time between 49530 AND 49530+28800
and sm_carrier in ('DIAMOND','AIRBORNE')
group by
w_warehouse_name
,w_warehouse_sq_ft
,w_city
,w_county
,w_state
,w_country
,d_year
) x
group by
w_warehouse_name
,w_warehouse_sq_ft
,w_city
,w_county
,w_state
,w_country
,ship_carriers
,year
order by w_warehouse_name
limit 100;
-- end query 1 in stream 0 using template ../query_templates/query66.tpl
|