blob: 2aa514659d1ac88507a8684704a1ee5a8241aa1e [file] [log] [blame]
====
---- QUERY: TPCDS-Q51
WITH web_v1 as (
select
ws_item_sk item_sk, d_date,
sum(sum(ws_sales_price))
over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales
from web_sales
,date_dim
where ws_sold_date_sk=d_date_sk
and d_month_seq between 1200 and 1200+11
and ws_item_sk is not NULL
group by ws_item_sk, d_date),
store_v1 as (
select
ss_item_sk item_sk, d_date,
sum(sum(ss_sales_price))
over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales
from store_sales
,date_dim
where ss_sold_date_sk=d_date_sk
and d_month_seq between 1200 and 1200+11
and ss_item_sk is not NULL
group by ss_item_sk, d_date)
select *
from (select item_sk
,d_date
,web_sales
,store_sales
,max(web_sales)
over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative
,max(store_sales)
over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative
from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk
,case when web.d_date is not null then web.d_date else store.d_date end d_date
,web.cume_sales web_sales
,store.cume_sales store_sales
from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk
and web.d_date = store.d_date)
)x )y
where web_cumulative > store_cumulative
order by item_sk
,d_date
limit 100;
---- RESULTS
14,'2000-01-10',176.83,NULL,176.83,73.60
14,'2000-01-21',NULL,75.29,176.83,75.29
14,'2000-01-29',222.33,NULL,222.33,75.29
14,'2000-02-02',224.01,NULL,224.01,75.29
14,'2000-02-08',NULL,85.07,224.01,85.07
14,'2000-02-19',NULL,98.60,224.01,98.60
14,'2000-02-21',241.64,NULL,241.64,98.60
14,'2000-02-22',NULL,99.83,241.64,99.83
14,'2000-03-18',NULL,112.82,241.64,112.82
14,'2000-03-23',251.15,NULL,251.15,112.82
14,'2000-03-28',260.17,NULL,260.17,112.82
14,'2000-03-31',370.74,NULL,370.74,112.82
14,'2000-04-05',NULL,115.94,370.74,115.94
14,'2000-04-15',445.30,NULL,445.30,115.94
14,'2000-04-27',NULL,151.48,445.30,151.48
14,'2000-05-03',NULL,176.89,445.30,176.89
14,'2000-05-10',451.40,NULL,451.40,176.89
14,'2000-05-21',NULL,238.39,451.40,238.39
14,'2000-05-26',596.81,NULL,596.81,238.39
14,'2000-05-29',NULL,242.51,596.81,242.51
14,'2000-06-05',NULL,304.64,596.81,304.64
14,'2000-07-03',623.77,NULL,623.77,304.64
14,'2000-07-07',NULL,307.77,623.77,307.77
14,'2000-07-18',NULL,320.04,623.77,320.04
14,'2000-07-25',673.08,NULL,673.08,320.04
14,'2000-08-10',NULL,411.48,673.08,411.48
14,'2000-08-14',NULL,465.85,673.08,465.85
14,'2000-08-21',NULL,541.45,673.08,541.45
14,'2000-08-26',NULL,574.56,673.08,574.56
19,'2000-01-02',56.96,49.68,56.96,49.68
25,'2000-01-21',97.29,NULL,97.29,4.49
25,'2000-01-28',192.46,NULL,192.46,4.49
25,'2000-02-09',NULL,24.23,192.46,24.23
25,'2000-02-11',NULL,98.99,192.46,98.99
25,'2000-02-21',NULL,170.60,192.46,170.60
25,'2000-02-22',NULL,185.05,192.46,185.05
35,'2000-01-14',NULL,55.24,177.88,55.24
35,'2000-01-16',NULL,95.92,177.88,95.92
35,'2000-01-18',NULL,126.45,177.88,126.45
35,'2000-01-19',NULL,167.07,177.88,167.07
35,'2000-02-17',NULL,173.97,177.88,173.97
35,'2000-02-22',270.43,NULL,270.43,173.97
35,'2000-02-23',NULL,180.61,270.43,180.61
35,'2000-03-03',NULL,181.99,270.43,181.99
35,'2000-03-05',NULL,221.24,270.43,221.24
35,'2000-03-06',NULL,266.41,270.43,266.41
37,'2000-01-02',31.75,11.89,31.75,11.89
37,'2000-01-04',NULL,17.15,31.75,17.15
37,'2000-01-05',34.34,NULL,34.34,17.15
37,'2000-01-06',NULL,29.67,34.34,29.67
41,'2000-01-21',NULL,15.54,123.34,15.54
41,'2000-02-03',NULL,21.04,123.34,21.04
41,'2000-02-16',NULL,33.46,123.34,33.46
41,'2000-02-20',NULL,37.46,123.34,37.46
41,'2000-02-22',NULL,58.57,123.34,58.57
41,'2000-03-05',NULL,70.06,123.34,70.06
41,'2000-03-17',178.84,150.76,178.84,150.76
41,'2000-04-26',263.14,NULL,263.14,254.88
41,'2000-07-12',474.83,NULL,474.83,393.87
41,'2000-07-18',NULL,421.23,474.83,421.23
41,'2000-08-15',NULL,430.77,474.83,430.77
49,'2000-01-18',NULL,2.51,4.58,2.51
49,'2000-01-31',72.47,NULL,72.47,13.05
49,'2000-02-13',NULL,70.68,72.47,70.68
49,'2000-02-29',NULL,71.86,72.47,71.86
49,'2000-04-17',225.29,NULL,225.29,219.03
53,'2000-01-02',12.85,1.13,12.85,1.13
53,'2000-01-08',119.24,NULL,119.24,1.13
53,'2000-01-09',126.98,NULL,126.98,1.13
53,'2000-01-15',NULL,3.20,126.98,3.20
53,'2000-02-04',NULL,22.89,126.98,22.89
53,'2000-02-05',NULL,64.45,126.98,64.45
53,'2000-02-12',NULL,66.06,126.98,66.06
56,'2000-01-02',41.57,17.31,41.57,17.31
61,'2000-02-17',421.60,NULL,421.60,344.03
61,'2000-03-01',NULL,411.33,421.60,411.33
61,'2000-04-22',600.20,NULL,600.20,573.28
71,'2000-01-02',13.92,2.88,13.92,2.88
85,'2000-02-03',NULL,42.30,65.50,42.30
85,'2000-02-16',NULL,42.95,65.50,42.95
85,'2000-04-19',335.16,NULL,335.16,247.67
85,'2000-04-23',NULL,252.83,335.16,252.83
85,'2000-05-02',NULL,289.65,335.16,289.65
85,'2000-05-11',NULL,312.62,335.16,312.62
86,'2000-01-19',31.70,NULL,31.70,25.97
86,'2000-02-03',151.26,NULL,151.26,91.16
86,'2000-02-04',NULL,112.15,151.26,112.15
89,'2000-01-12',NULL,28.84,181.56,28.84
89,'2000-01-23',NULL,67.19,181.56,67.19
89,'2000-01-30',NULL,104.65,181.56,104.65
89,'2000-02-22',NULL,146.96,181.56,146.96
89,'2000-02-25',NULL,147.02,181.56,147.02
89,'2000-03-19',NULL,172.85,181.56,172.85
89,'2000-03-20',191.66,NULL,191.66,172.85
89,'2000-04-11',295.81,NULL,295.81,172.85
89,'2000-04-13',NULL,203.86,295.81,203.86
89,'2000-04-20',373.30,NULL,373.30,203.86
89,'2000-04-23',NULL,219.74,373.30,219.74
89,'2000-04-26',NULL,235.97,373.30,235.97
89,'2000-05-04',NULL,248.05,373.30,248.05
---- TYPES
BIGINT, STRING, DECIMAL, DECIMAL, DECIMAL, DECIMAL
====