Skip to content

Commit f956c48

Browse files
authored
Second 25 queries of TPC-DS (#660)
1 parent 089fa57 commit f956c48

25 files changed

+1215
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
-- start query 1 in stream 0 using template query26.tpl and seed 1930872976
5+
select item.i_item_id,
6+
avg(cs_quantity) agg1,
7+
avg(cs_list_price) agg2,
8+
avg(cs_coupon_amt) agg3,
9+
avg(cs_sales_price) agg4
10+
from {{catalog_sales}} as catalog_sales
11+
cross join {{customer_demographics}} as customer_demographics
12+
cross join {{date_dim}} as date_dim
13+
cross join {{item}} as item
14+
cross join {{promotion}} as promotion
15+
where cs_sold_date_sk = d_date_sk and
16+
cs_item_sk = i_item_sk and
17+
cs_bill_cdemo_sk = cd_demo_sk and
18+
cs_promo_sk = p_promo_sk and
19+
cd_gender = 'F' and
20+
cd_marital_status = 'S' and
21+
cd_education_status = 'College' and
22+
(p_channel_email = 'N' or p_channel_event = 'N') and
23+
d_year = 1998
24+
group by item.i_item_id
25+
order by item.i_item_id
26+
limit 100;
27+
28+
-- end query 1 in stream 0 using template query26.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
-- start query 1 in stream 0 using template query27.tpl and seed 2017787633
5+
select item.i_item_id,
6+
store.s_state, grouping(store.s_state) g_state,
7+
avg(ss_quantity) agg1,
8+
avg(ss_list_price) agg2,
9+
avg(ss_coupon_amt) agg3,
10+
avg(ss_sales_price) agg4
11+
from {{store_sales}} as store_sales
12+
cross join {{customer_demographics}} as customer_demographics
13+
cross join {{date_dim}} as date_dim
14+
cross join {{store}} as store
15+
cross join {{item}} as item
16+
where ss_sold_date_sk = d_date_sk and
17+
ss_item_sk = i_item_sk and
18+
ss_store_sk = s_store_sk and
19+
ss_cdemo_sk = cd_demo_sk and
20+
cd_gender = 'F' and
21+
cd_marital_status = 'U' and
22+
cd_education_status = '2 yr Degree' and
23+
d_year = 2000 and
24+
s_state in ('AL','IN', 'SC', 'NY', 'OH', 'FL')
25+
group by rollup (item.i_item_id, store.s_state)
26+
order by item.i_item_id
27+
,store.s_state
28+
limit 100;
29+
30+
-- end query 1 in stream 0 using template query27.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
-- start query 1 in stream 0 using template query28.tpl and seed 444293455
5+
select *
6+
from (select avg(ss_list_price) B1_LP
7+
,count(ss_list_price) B1_CNT
8+
,count(distinct ss_list_price) B1_CNTD
9+
from {{store_sales}} as store_sales
10+
where ss_quantity between 0 and 5
11+
and (ss_list_price between 73 and 73+10
12+
or ss_coupon_amt between 7826 and 7826+1000
13+
or ss_wholesale_cost between 70 and 70+20)) B1 cross join
14+
(select avg(ss_list_price) B2_LP
15+
,count(ss_list_price) B2_CNT
16+
,count(distinct ss_list_price) B2_CNTD
17+
from {{store_sales}} as store_sales
18+
where ss_quantity between 6 and 10
19+
and (ss_list_price between 152 and 152+10
20+
or ss_coupon_amt between 2196 and 2196+1000
21+
or ss_wholesale_cost between 56 and 56+20)) B2 cross join
22+
(select avg(ss_list_price) B3_LP
23+
,count(ss_list_price) B3_CNT
24+
,count(distinct ss_list_price) B3_CNTD
25+
from {{store_sales}} as store_sales
26+
where ss_quantity between 11 and 15
27+
and (ss_list_price between 53 and 53+10
28+
or ss_coupon_amt between 3430 and 3430+1000
29+
or ss_wholesale_cost between 13 and 13+20)) B3 cross join
30+
(select avg(ss_list_price) B4_LP
31+
,count(ss_list_price) B4_CNT
32+
,count(distinct ss_list_price) B4_CNTD
33+
from {{store_sales}} as store_sales
34+
where ss_quantity between 16 and 20
35+
and (ss_list_price between 182 and 182+10
36+
or ss_coupon_amt between 3262 and 3262+1000
37+
or ss_wholesale_cost between 20 and 20+20)) B4 cross join
38+
(select avg(ss_list_price) B5_LP
39+
,count(ss_list_price) B5_CNT
40+
,count(distinct ss_list_price) B5_CNTD
41+
from {{store_sales}} as store_sales
42+
where ss_quantity between 21 and 25
43+
and (ss_list_price between 85 and 85+10
44+
or ss_coupon_amt between 3310 and 3310+1000
45+
or ss_wholesale_cost between 37 and 37+20)) B5 cross join
46+
(select avg(ss_list_price) B6_LP
47+
,count(ss_list_price) B6_CNT
48+
,count(distinct ss_list_price) B6_CNTD
49+
from {{store_sales}} as store_sales
50+
where ss_quantity between 26 and 30
51+
and (ss_list_price between 180 and 180+10
52+
or ss_coupon_amt between 12592 and 12592+1000
53+
or ss_wholesale_cost between 22 and 22+20)) B6
54+
limit 100;
55+
56+
-- end query 1 in stream 0 using template query28.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
-- start query 1 in stream 0 using template query29.tpl and seed 2031708268
5+
select
6+
item.i_item_id
7+
,item.i_item_desc
8+
,store.s_store_id
9+
,store.s_store_name
10+
,stddev_samp(ss_quantity) as store_sales_quantity
11+
,stddev_samp(sr_return_quantity) as store_returns_quantity
12+
,stddev_samp(cs_quantity) as catalog_sales_quantity
13+
from
14+
{{store_sales}} as store_sales
15+
cross join {{store_returns}} as store_returns
16+
cross join {{catalog_sales}} as catalog_sales
17+
cross join {{date_dim}} d1
18+
cross join {{date_dim}} d2
19+
cross join {{date_dim}} d3
20+
cross join {{store}} as store
21+
cross join {{item}} as item
22+
where
23+
d1.d_moy = 4
24+
and d1.d_year = 1998
25+
and d1.d_date_sk = ss_sold_date_sk
26+
and i_item_sk = ss_item_sk
27+
and s_store_sk = ss_store_sk
28+
and ss_customer_sk = sr_customer_sk
29+
and ss_item_sk = sr_item_sk
30+
and ss_ticket_number = sr_ticket_number
31+
and sr_returned_date_sk = d2.d_date_sk
32+
and d2.d_moy between 4 and 4 + 3
33+
and d2.d_year = 1998
34+
and sr_customer_sk = cs_bill_customer_sk
35+
and sr_item_sk = cs_item_sk
36+
and cs_sold_date_sk = d3.d_date_sk
37+
and d3.d_year in (1998,1998+1,1998+2)
38+
group by
39+
item.i_item_id
40+
,item.i_item_desc
41+
,store.s_store_id
42+
,store.s_store_name
43+
order by
44+
item.i_item_id
45+
,item.i_item_desc
46+
,store.s_store_id
47+
,store.s_store_name
48+
limit 100;
49+
50+
-- end query 1 in stream 0 using template query29.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
$customer_total_return =
5+
(select web_returns.wr_returning_customer_sk as ctr_customer_sk
6+
,customer_address.ca_state as ctr_state,
7+
sum(wr_return_amt) as ctr_total_return
8+
from {{web_returns}} as web_returns
9+
cross join {{date_dim}} as date_dim
10+
cross join {{customer_address}} as customer_address
11+
where wr_returned_date_sk = d_date_sk
12+
and d_year =2000
13+
and wr_returning_addr_sk = ca_address_sk
14+
group by web_returns.wr_returning_customer_sk
15+
,customer_address.ca_state);
16+
17+
$avg_total_return_by_state =
18+
(select ctr_state, avg(ctr_total_return) avg_return
19+
from $customer_total_return
20+
group by ctr_state);
21+
22+
-- start query 1 in stream 0 using template query30.tpl and seed 1819994127
23+
select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag
24+
,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address
25+
,c_last_review_date,ctr_total_return
26+
from $customer_total_return ctr1
27+
join $avg_total_return_by_state ctr2 on ctr1.ctr_state = ctr2.ctr_state
28+
cross join {{customer_address}} as customer_address
29+
cross join {{customer}} as customer
30+
where ctr1.ctr_total_return > 1.2*ctr2.avg_return
31+
and ca_address_sk = c_current_addr_sk
32+
and ca_state = 'GA'
33+
and ctr1.ctr_customer_sk = c_customer_sk
34+
order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag
35+
,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address
36+
,c_last_review_date,ctr_total_return
37+
limit 100;
38+
39+
-- end query 1 in stream 0 using template query30.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
$ss =
5+
(select customer_address.ca_county ca_county, date_dim.d_qoy d_qoy, date_dim.d_year d_year,sum(ss_ext_sales_price) as store_sales
6+
from {{store_sales}} as store_sales
7+
cross join {{date_dim}} as date_dim
8+
cross join {{customer_address}} as customer_address
9+
where ss_sold_date_sk = d_date_sk
10+
and ss_addr_sk=ca_address_sk
11+
group by customer_address.ca_county,date_dim.d_qoy, date_dim.d_year);
12+
13+
$ws =
14+
(select customer_address.ca_county ca_county,date_dim.d_qoy d_qoy, date_dim.d_year d_year,sum(ws_ext_sales_price) as web_sales
15+
from {{web_sales}} as web_sales
16+
cross join {{date_dim}} as date_dim
17+
cross join {{customer_address}} as customer_address
18+
where ws_sold_date_sk = d_date_sk
19+
and ws_bill_addr_sk=ca_address_sk
20+
group by customer_address.ca_county,date_dim.d_qoy, date_dim.d_year);
21+
22+
-- start query 1 in stream 0 using template query31.tpl and seed 1819994127
23+
select
24+
ss1.ca_county
25+
,ss1.d_year
26+
,ws2.web_sales/ws1.web_sales web_q1_q2_increase
27+
,ss2.store_sales/ss1.store_sales store_q1_q2_increase
28+
,ws3.web_sales/ws2.web_sales web_q2_q3_increase
29+
,ss3.store_sales/ss2.store_sales store_q2_q3_increase
30+
from
31+
$ss ss1
32+
cross join $ss ss2
33+
cross join $ss ss3
34+
cross join $ws ws1
35+
cross join $ws ws2
36+
cross join $ws ws3
37+
where
38+
ss1.d_qoy = 1
39+
and ss1.d_year = 1999
40+
and ss1.ca_county = ss2.ca_county
41+
and ss2.d_qoy = 2
42+
and ss2.d_year = 1999
43+
and ss2.ca_county = ss3.ca_county
44+
and ss3.d_qoy = 3
45+
and ss3.d_year = 1999
46+
and ss1.ca_county = ws1.ca_county
47+
and ws1.d_qoy = 1
48+
and ws1.d_year = 1999
49+
and ws1.ca_county = ws2.ca_county
50+
and ws2.d_qoy = 2
51+
and ws2.d_year = 1999
52+
and ws1.ca_county = ws3.ca_county
53+
and ws3.d_qoy = 3
54+
and ws3.d_year =1999
55+
and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end
56+
> case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end
57+
and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end
58+
> case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end
59+
order by ss1.d_year;
60+
61+
-- end query 1 in stream 0 using template query31.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
$avg_discount_by_item = (
5+
select
6+
item.i_item_sk i_item_sk,
7+
avg(cs_ext_discount_amt) as avg_discout
8+
from
9+
{{catalog_sales}} as catalog_sales
10+
cross join {{date_dim}} as date_dim
11+
cross join {{item}} as item
12+
where cast (d_date as date) between cast('2002-03-29' as date) and
13+
(cast('2002-03-29' as date) + DateTime::IntervalFromDays(90))
14+
and d_date_sk = cs_sold_date_sk
15+
group by item.i_item_sk
16+
);
17+
18+
-- start query 1 in stream 0 using template query32.tpl and seed 2031708268
19+
select sum(cs_ext_discount_amt) as `excess discount amount`
20+
from
21+
{{catalog_sales}} cs
22+
cross join {{item}} as item
23+
cross join {{date_dim}} as date_dim
24+
join $avg_discount_by_item adi on cs.cs_item_sk = adi.i_item_sk
25+
where
26+
i_manufact_id = 66
27+
and item.i_item_sk = cs.cs_item_sk
28+
and cast (d_date as date) between cast('2002-03-29' as date) and
29+
(cast('2002-03-29' as date) + DateTime::IntervalFromDays(90))
30+
and d_date_sk = cs_sold_date_sk
31+
and cs_ext_discount_amt
32+
> 1.3 * adi.avg_discout
33+
limit 100;
34+
35+
-- end query 1 in stream 0 using template query32.tpl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{% include 'header.sql.jinja' %}
2+
3+
-- NB: Subquerys
4+
$ss = (
5+
select
6+
item.i_manufact_id i_manufact_id,sum(ss_ext_sales_price) total_sales
7+
from
8+
{{store_sales}} as store_sales cross join
9+
{{date_dim}} as date_dim cross join
10+
{{customer_address}} as customer_address cross join
11+
{{item}} as item
12+
where
13+
item.i_manufact_id in (select
14+
i_manufact_id
15+
from
16+
{{item}} as item
17+
where i_category in ('Home'))
18+
and ss_item_sk = i_item_sk
19+
and ss_sold_date_sk = d_date_sk
20+
and d_year = 1998
21+
and d_moy = 5
22+
and ss_addr_sk = ca_address_sk
23+
and ca_gmt_offset = -6
24+
group by item.i_manufact_id);
25+
26+
$cs = (
27+
select
28+
item.i_manufact_id i_manufact_id,sum(cs_ext_sales_price) total_sales
29+
from
30+
{{catalog_sales}} as catalog_sales cross join
31+
{{date_dim}} as date_dim cross join
32+
{{customer_address}} as customer_address cross join
33+
{{item}} as item
34+
where
35+
item.i_manufact_id in (select
36+
i_manufact_id
37+
from
38+
{{item}} as item
39+
where i_category in ('Home'))
40+
and cs_item_sk = i_item_sk
41+
and cs_sold_date_sk = d_date_sk
42+
and d_year = 1998
43+
and d_moy = 5
44+
and cs_bill_addr_sk = ca_address_sk
45+
and ca_gmt_offset = -6
46+
group by item.i_manufact_id);
47+
48+
$ws = (
49+
select
50+
item.i_manufact_id i_manufact_id,sum(ws_ext_sales_price) total_sales
51+
from
52+
{{web_sales}} as web_sales cross join
53+
{{date_dim}} as date_dim cross join
54+
{{customer_address}} as customer_address cross join
55+
{{item}} as item
56+
where
57+
item.i_manufact_id in (select
58+
i_manufact_id
59+
from
60+
{{item}} as item
61+
where i_category in ('Home'))
62+
and ws_item_sk = i_item_sk
63+
and ws_sold_date_sk = d_date_sk
64+
and d_year = 1998
65+
and d_moy = 5
66+
and ws_bill_addr_sk = ca_address_sk
67+
and ca_gmt_offset = -6
68+
group by item.i_manufact_id);
69+
70+
71+
-- start query 1 in stream 0 using template query33.tpl and seed 1930872976
72+
select i_manufact_id ,sum(total_sales) total_sales
73+
from (select * from $ss
74+
union all
75+
select * from $cs
76+
union all
77+
select * from $ws) tmp1
78+
group by i_manufact_id
79+
order by total_sales
80+
limit 100;
81+
82+
-- end query 1 in stream 0 using template query33.tpl

0 commit comments

Comments
 (0)