@@ -248,7 +248,7 @@ with ssr as
248
248
store
249
249
where date_sk = d_date_sk
250
250
and d_date between cast(' 2000-08-19' as date )
251
- and (cast(' 2000-08-19' as date ) + 14 days)
251
+ and (cast(' 2000-08-19' as date ) + interval ' 14 days' )
252
252
and store_sk = s_store_sk
253
253
group by s_store_id)
254
254
,
@@ -279,7 +279,7 @@ with ssr as
279
279
catalog_page
280
280
where date_sk = d_date_sk
281
281
and d_date between cast(' 2000-08-19' as date )
282
- and (cast(' 2000-08-19' as date ) + 14 days)
282
+ and (cast(' 2000-08-19' as date ) + interval ' 14 days' )
283
283
and page_sk = cp_catalog_page_sk
284
284
group by cp_catalog_page_id)
285
285
,
@@ -312,7 +312,7 @@ with ssr as
312
312
web_site
313
313
where date_sk = d_date_sk
314
314
and d_date between cast(' 2000-08-19' as date )
315
- and (cast(' 2000-08-19' as date ) + 14 days)
315
+ and (cast(' 2000-08-19' as date ) + interval ' 14 days' )
316
316
and wsr_web_site_sk = web_site_sk
317
317
group by web_site_id)
318
318
select channel
@@ -712,7 +712,7 @@ where
712
712
and i_category in (' Men' , ' Books' , ' Electronics' )
713
713
and ws_sold_date_sk = d_date_sk
714
714
and d_date between cast(' 2001-06-15' as date )
715
- and (cast(' 2001-06-15' as date ) + 30 days)
715
+ and (cast(' 2001-06-15' as date ) + interval ' 30 days' )
716
716
group by
717
717
i_item_id
718
718
,i_item_desc
@@ -812,7 +812,7 @@ with cross_items as
812
812
,date_dim d3
813
813
where ws_item_sk = iws .i_item_sk
814
814
and ws_sold_date_sk = d3 .d_date_sk
815
- and d3 .d_year between 1999 AND 1999 + 2 )
815
+ and d3 .d_year between 1999 AND 1999 + 2 ) as sub
816
816
where i_brand_id = brand_id
817
817
and i_class_id = class_id
818
818
and i_category_id = category_id
@@ -838,7 +838,7 @@ with cross_items as
838
838
from web_sales
839
839
,date_dim
840
840
where ws_sold_date_sk = d_date_sk
841
- and d_year between 1999 and 1999 + 2 ) x)
841
+ and d_year between 1999 and 1999 + 2 ) as x)
842
842
select channel, i_brand_id,i_class_id,i_category_id,sum (sales), sum (number_sales)
843
843
from (
844
844
select ' store' channel, i_brand_id,i_class_id
@@ -882,6 +882,7 @@ with cross_items as
882
882
group by rollup (channel, i_brand_id,i_class_id,i_category_id)
883
883
order by channel,i_brand_id,i_class_id,i_category_id
884
884
limit 100 ;
885
+
885
886
with cross_items as
886
887
(select i_item_sk ss_item_sk
887
888
from item,
@@ -913,7 +914,7 @@ with cross_items as
913
914
,date_dim d3
914
915
where ws_item_sk = iws .i_item_sk
915
916
and ws_sold_date_sk = d3 .d_date_sk
916
- and d3 .d_year between 1999 AND 1999 + 2 ) x
917
+ and d3 .d_year between 1999 AND 1999 + 2 ) as x
917
918
where i_brand_id = brand_id
918
919
and i_class_id = class_id
919
920
and i_category_id = category_id
@@ -939,7 +940,7 @@ with cross_items as
939
940
from web_sales
940
941
,date_dim
941
942
where ws_sold_date_sk = d_date_sk
942
- and d_year between 1999 and 1999 + 2 ) x)
943
+ and d_year between 1999 and 1999 + 2 ) as x)
943
944
select this_year .channel ty_channel
944
945
,this_year .i_brand_id ty_brand
945
946
,this_year .i_class_id ty_class
@@ -1022,7 +1023,7 @@ from
1022
1023
,call_center
1023
1024
where
1024
1025
d_date between ' 2002-4-01' and
1025
- (cast(' 2002-4-01' as date ) + 60 days)
1026
+ (cast(' 2002-4-01' as date ) + interval ' 60 days' )
1026
1027
and cs1 .cs_ship_date_sk = d_date_sk
1027
1028
and cs1 .cs_ship_addr_sk = ca_address_sk
1028
1029
and ca_state = ' PA'
@@ -1161,7 +1162,7 @@ select i_item_id
1161
1162
and i_category in (' Books' , ' Music' , ' Sports' )
1162
1163
and cs_sold_date_sk = d_date_sk
1163
1164
and d_date between cast(' 2002-06-18' as date )
1164
- and (cast(' 2002-06-18' as date ) + 30 days)
1165
+ and (cast(' 2002-06-18' as date ) + interval ' 30 days' )
1165
1166
group by i_item_id
1166
1167
,i_item_desc
1167
1168
,i_category
@@ -1193,8 +1194,8 @@ select *
1193
1194
and i_item_sk = inv_item_sk
1194
1195
and inv_warehouse_sk = w_warehouse_sk
1195
1196
and inv_date_sk = d_date_sk
1196
- and d_date between (cast (' 1999-06-22' as date ) - 30 days)
1197
- and (cast (' 1999-06-22' as date ) + 30 days)
1197
+ and d_date between (cast (' 1999-06-22' as date ) - interval ' 30 days' )
1198
+ and (cast (' 1999-06-22' as date ) + interval ' 30 days' )
1198
1199
group by w_warehouse_name, i_item_id) x
1199
1200
where (case when inv_before > 0
1200
1201
then inv_after / inv_before
@@ -1238,14 +1239,15 @@ with frequent_ss_items as
1238
1239
having count (* ) > 4 ),
1239
1240
max_store_sales as
1240
1241
(select max (csales) tpcds_cmax
1241
- from (select c_customer_sk,sum (ss_quantity* ss_sales_price) csales
1242
+ from (select c_customer_sk,sum (ss_quantity* ss_sales_price) as csales
1242
1243
from store_sales
1243
1244
,customer
1244
1245
,date_dim
1245
1246
where ss_customer_sk = c_customer_sk
1246
1247
and ss_sold_date_sk = d_date_sk
1247
1248
and d_year in (2000 ,2000 + 1 ,2000 + 2 ,2000 + 3 )
1248
- group by c_customer_sk)),
1249
+ group by c_customer_sk) as scsales
1250
+ ),
1249
1251
best_ss_customer as
1250
1252
(select c_customer_sk,sum (ss_quantity* ss_sales_price) ssales
1251
1253
from store_sales
@@ -1273,8 +1275,9 @@ from
1273
1275
and d_moy = 7
1274
1276
and ws_sold_date_sk = d_date_sk
1275
1277
and ws_item_sk in (select item_sk from frequent_ss_items)
1276
- and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer))
1278
+ and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) as foo
1277
1279
limit 100 ;
1280
+
1278
1281
with frequent_ss_items as
1279
1282
(select substr(i_item_desc,1 ,30 ) itemdesc,i_item_sk item_sk,d_date solddate,count (* ) cnt
1280
1283
from store_sales
@@ -1294,7 +1297,7 @@ with frequent_ss_items as
1294
1297
where ss_customer_sk = c_customer_sk
1295
1298
and ss_sold_date_sk = d_date_sk
1296
1299
and d_year in (2000 ,2000 + 1 ,2000 + 2 ,2000 + 3 )
1297
- group by c_customer_sk)),
1300
+ group by c_customer_sk) as scsales ),
1298
1301
best_ss_customer as
1299
1302
(select c_customer_sk,sum (ss_quantity* ss_sales_price) ssales
1300
1303
from store_sales
@@ -1327,7 +1330,7 @@ with frequent_ss_items as
1327
1330
and ws_item_sk in (select item_sk from frequent_ss_items)
1328
1331
and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)
1329
1332
and ws_bill_customer_sk = c_customer_sk
1330
- group by c_last_name,c_first_name)
1333
+ group by c_last_name,c_first_name) as sub
1331
1334
order by c_last_name,c_first_name,sales
1332
1335
limit 100 ;
1333
1336
@@ -1724,7 +1727,7 @@ where
1724
1727
i_manufact_id = 722
1725
1728
and i_item_sk = cs_item_sk
1726
1729
and d_date between ' 2001-03-09' and
1727
- (cast(' 2001-03-09' as date ) + 90 days)
1730
+ (cast(' 2001-03-09' as date ) + interval ' 90 days' )
1728
1731
and d_date_sk = cs_sold_date_sk
1729
1732
and cs_ext_discount_amt
1730
1733
> (
@@ -1736,7 +1739,7 @@ and cs_ext_discount_amt
1736
1739
where
1737
1740
cs_item_sk = i_item_sk
1738
1741
and d_date between ' 2001-03-09' and
1739
- (cast(' 2001-03-09' as date ) + 90 days)
1742
+ (cast(' 2001-03-09' as date ) + interval ' 90 days' )
1740
1743
and d_date_sk = cs_sold_date_sk
1741
1744
)
1742
1745
limit 100 ;
@@ -1944,7 +1947,7 @@ select i_item_id
1944
1947
where i_current_price between 29 and 29 + 30
1945
1948
and inv_item_sk = i_item_sk
1946
1949
and d_date_sk= inv_date_sk
1947
- and d_date between cast(' 2002-03-29' as date ) and (cast(' 2002-03-29' as date ) + 60 days)
1950
+ and d_date between cast(' 2002-03-29' as date ) and (cast(' 2002-03-29' as date ) + interval ' 60 days' )
1948
1951
and i_manufact_id in (705 ,742 ,777 ,944 )
1949
1952
and inv_quantity_on_hand between 100 and 500
1950
1953
and cs_item_sk = i_item_sk
@@ -2050,8 +2053,8 @@ select
2050
2053
and i_item_sk = cs_item_sk
2051
2054
and cs_warehouse_sk = w_warehouse_sk
2052
2055
and cs_sold_date_sk = d_date_sk
2053
- and d_date between (cast (' 2001-05-02' as date ) - 30 days)
2054
- and (cast (' 2001-05-02' as date ) + 30 days)
2056
+ and d_date between (cast (' 2001-05-02' as date ) - interval ' 30 days' )
2057
+ and (cast (' 2001-05-02' as date ) + interval ' 30 days' )
2055
2058
group by
2056
2059
w_state,i_item_id
2057
2060
order by w_state,i_item_id
@@ -2395,7 +2398,7 @@ select channel, item, return_ratio, return_rank, currency_rank from
2395
2398
and d_moy = 11
2396
2399
group by ws .ws_item_sk
2397
2400
) in_web
2398
- ) web
2401
+ ) as web
2399
2402
where
2400
2403
(
2401
2404
web .return_rank <= 10
@@ -2438,7 +2441,7 @@ select channel, item, return_ratio, return_rank, currency_rank from
2438
2441
and d_moy = 11
2439
2442
group by cs .cs_item_sk
2440
2443
) in_cat
2441
- ) catalog
2444
+ ) as catalog
2442
2445
where
2443
2446
(
2444
2447
catalog .return_rank <= 10
@@ -2477,13 +2480,13 @@ select channel, item, return_ratio, return_rank, currency_rank from
2477
2480
and d_moy = 11
2478
2481
group by sts .ss_item_sk
2479
2482
) in_store
2480
- ) store
2483
+ ) as store
2481
2484
where (
2482
2485
store .return_rank <= 10
2483
2486
or
2484
2487
store .currency_rank <= 10
2485
2488
)
2486
- )
2489
+ )as tab
2487
2490
order by 1 ,4 ,5 ,2
2488
2491
limit 100 ;
2489
2492
@@ -3927,7 +3930,7 @@ with ss as
3927
3930
store
3928
3931
where ss_sold_date_sk = d_date_sk
3929
3932
and d_date between cast(' 2000-08-10' as date )
3930
- and (cast(' 2000-08-10' as date ) + 30 days)
3933
+ and (cast(' 2000-08-10' as date ) + interval ' 30 days' )
3931
3934
and ss_store_sk = s_store_sk
3932
3935
group by s_store_sk)
3933
3936
,
@@ -3940,7 +3943,7 @@ with ss as
3940
3943
store
3941
3944
where sr_returned_date_sk = d_date_sk
3942
3945
and d_date between cast(' 2000-08-10' as date )
3943
- and (cast(' 2000-08-10' as date ) + 30 days)
3946
+ and (cast(' 2000-08-10' as date ) + interval ' 30 days' )
3944
3947
and sr_store_sk = s_store_sk
3945
3948
group by s_store_sk),
3946
3949
cs as
@@ -3951,7 +3954,7 @@ with ss as
3951
3954
date_dim
3952
3955
where cs_sold_date_sk = d_date_sk
3953
3956
and d_date between cast(' 2000-08-10' as date )
3954
- and (cast(' 2000-08-10' as date ) + 30 days)
3957
+ and (cast(' 2000-08-10' as date ) + interval ' 30 days' )
3955
3958
group by cs_call_center_sk
3956
3959
),
3957
3960
cr as
@@ -3962,7 +3965,7 @@ with ss as
3962
3965
date_dim
3963
3966
where cr_returned_date_sk = d_date_sk
3964
3967
and d_date between cast(' 2000-08-10' as date )
3965
- and (cast(' 2000-08-10' as date ) + 30 days)
3968
+ and (cast(' 2000-08-10' as date ) + interval ' 30 days' )
3966
3969
group by cr_call_center_sk
3967
3970
),
3968
3971
ws as
@@ -3974,7 +3977,7 @@ with ss as
3974
3977
web_page
3975
3978
where ws_sold_date_sk = d_date_sk
3976
3979
and d_date between cast(' 2000-08-10' as date )
3977
- and (cast(' 2000-08-10' as date ) + 30 days)
3980
+ and (cast(' 2000-08-10' as date ) + interval ' 30 days' )
3978
3981
and ws_web_page_sk = wp_web_page_sk
3979
3982
group by wp_web_page_sk),
3980
3983
wr as
@@ -3986,7 +3989,7 @@ with ss as
3986
3989
web_page
3987
3990
where wr_returned_date_sk = d_date_sk
3988
3991
and d_date between cast(' 2000-08-10' as date )
3989
- and (cast(' 2000-08-10' as date ) + 30 days)
3992
+ and (cast(' 2000-08-10' as date ) + interval ' 30 days' )
3990
3993
and wr_web_page_sk = wp_web_page_sk
3991
3994
group by wp_web_page_sk)
3992
3995
select channel
@@ -4014,7 +4017,7 @@ with ss as
4014
4017
select ' web channel' as channel
4015
4018
, ws .wp_web_page_sk as id
4016
4019
, sales
4017
- , coalesce(returns, 0 ) returns
4020
+ , coalesce(returns, 0 ) as returns
4018
4021
, (profit - coalesce(profit_loss,0 )) as profit
4019
4022
from ws left join wr
4020
4023
on ws .wp_web_page_sk = wr .wp_web_page_sk
@@ -4120,7 +4123,7 @@ with ssr as
4120
4123
promotion
4121
4124
where ss_sold_date_sk = d_date_sk
4122
4125
and d_date between cast(' 2002-08-14' as date )
4123
- and (cast(' 2002-08-14' as date ) + 30 days)
4126
+ and (cast(' 2002-08-14' as date ) + interval ' 30 days' )
4124
4127
and ss_store_sk = s_store_sk
4125
4128
and ss_item_sk = i_item_sk
4126
4129
and i_current_price > 50
@@ -4141,7 +4144,7 @@ with ssr as
4141
4144
promotion
4142
4145
where cs_sold_date_sk = d_date_sk
4143
4146
and d_date between cast(' 2002-08-14' as date )
4144
- and (cast(' 2002-08-14' as date ) + 30 days)
4147
+ and (cast(' 2002-08-14' as date ) + interval ' 30 days' )
4145
4148
and cs_catalog_page_sk = cp_catalog_page_sk
4146
4149
and cs_item_sk = i_item_sk
4147
4150
and i_current_price > 50
@@ -4162,7 +4165,7 @@ group by cp_catalog_page_id)
4162
4165
promotion
4163
4166
where ws_sold_date_sk = d_date_sk
4164
4167
and d_date between cast(' 2002-08-14' as date )
4165
- and (cast(' 2002-08-14' as date ) + 30 days)
4168
+ and (cast(' 2002-08-14' as date ) + interval ' 30 days' )
4166
4169
and ws_web_site_sk = web_site_sk
4167
4170
and ws_item_sk = i_item_sk
4168
4171
and i_current_price > 50
@@ -4241,7 +4244,7 @@ select i_item_id
4241
4244
where i_current_price between 58 and 58 + 30
4242
4245
and inv_item_sk = i_item_sk
4243
4246
and d_date_sk= inv_date_sk
4244
- and d_date between cast(' 2001-01-13' as date ) and (cast(' 2001-01-13' as date ) + 60 days)
4247
+ and d_date between cast(' 2001-01-13' as date ) and (cast(' 2001-01-13' as date ) + interval ' 60 days' )
4245
4248
and i_manufact_id in (259 ,559 ,580 ,485 )
4246
4249
and inv_quantity_on_hand between 100 and 500
4247
4250
and ss_item_sk = i_item_sk
@@ -4657,7 +4660,7 @@ where
4657
4660
i_manufact_id = 714
4658
4661
and i_item_sk = ws_item_sk
4659
4662
and d_date between ' 2000-02-01' and
4660
- (cast(' 2000-02-01' as date ) + 90 days)
4663
+ (cast(' 2000-02-01' as date ) + interval ' 90 days' )
4661
4664
and d_date_sk = ws_sold_date_sk
4662
4665
and ws_ext_discount_amt
4663
4666
> (
@@ -4669,7 +4672,7 @@ and ws_ext_discount_amt
4669
4672
WHERE
4670
4673
ws_item_sk = i_item_sk
4671
4674
and d_date between ' 2000-02-01' and
4672
- (cast(' 2000-02-01' as date ) + 90 days)
4675
+ (cast(' 2000-02-01' as date ) + interval ' 90 days' )
4673
4676
and d_date_sk = ws_sold_date_sk
4674
4677
)
4675
4678
order by sum (ws_ext_discount_amt)
@@ -4706,7 +4709,7 @@ from
4706
4709
,web_site
4707
4710
where
4708
4711
d_date between ' 2002-5-01' and
4709
- (cast(' 2002-5-01' as date ) + 60 days)
4712
+ (cast(' 2002-5-01' as date ) + interval ' 60 days' )
4710
4713
and ws1 .ws_ship_date_sk = d_date_sk
4711
4714
and ws1 .ws_ship_addr_sk = ca_address_sk
4712
4715
and ca_state = ' OK'
@@ -4740,7 +4743,7 @@ from
4740
4743
,web_site
4741
4744
where
4742
4745
d_date between ' 2001-4-01' and
4743
- (cast(' 2001-4-01' as date ) + 60 days)
4746
+ (cast(' 2001-4-01' as date ) + interval ' 60 days' )
4744
4747
and ws1 .ws_ship_date_sk = d_date_sk
4745
4748
and ws1 .ws_ship_addr_sk = ca_address_sk
4746
4749
and ca_state = ' VA'
@@ -4814,7 +4817,7 @@ where
4814
4817
and i_category in (' Men' , ' Sports' , ' Jewelry' )
4815
4818
and ss_sold_date_sk = d_date_sk
4816
4819
and d_date between cast(' 1999-02-05' as date )
4817
- and (cast(' 1999-02-05' as date ) + 30 days)
4820
+ and (cast(' 1999-02-05' as date ) + interval ' 60 days' )
4818
4821
group by
4819
4822
i_item_id
4820
4823
,i_item_desc
0 commit comments