diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q26.sql b/ydb/library/benchmarks/queries/tpcds/yql/q26.sql new file mode 100644 index 000000000000..9d0e3147caf1 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q26.sql @@ -0,0 +1,28 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query26.tpl and seed 1930872976 +select item.i_item_id, + avg(cs_quantity) agg1, + avg(cs_list_price) agg2, + avg(cs_coupon_amt) agg3, + avg(cs_sales_price) agg4 + from {{catalog_sales}} as catalog_sales + cross join {{customer_demographics}} as customer_demographics + cross join {{date_dim}} as date_dim + cross join {{item}} as item + cross join {{promotion}} as promotion + where cs_sold_date_sk = d_date_sk and + cs_item_sk = i_item_sk and + cs_bill_cdemo_sk = cd_demo_sk and + cs_promo_sk = p_promo_sk and + cd_gender = 'F' and + cd_marital_status = 'S' and + cd_education_status = 'College' and + (p_channel_email = 'N' or p_channel_event = 'N') and + d_year = 1998 + group by item.i_item_id + order by item.i_item_id + limit 100; + +-- end query 1 in stream 0 using template query26.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q27.sql b/ydb/library/benchmarks/queries/tpcds/yql/q27.sql new file mode 100644 index 000000000000..8d94eb16d593 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q27.sql @@ -0,0 +1,30 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query27.tpl and seed 2017787633 +select item.i_item_id, + store.s_state, grouping(store.s_state) g_state, + avg(ss_quantity) agg1, + avg(ss_list_price) agg2, + avg(ss_coupon_amt) agg3, + avg(ss_sales_price) agg4 + from {{store_sales}} as store_sales + cross join {{customer_demographics}} as customer_demographics + cross join {{date_dim}} as date_dim + cross join {{store}} as store + cross join {{item}} as item + where ss_sold_date_sk = d_date_sk and + ss_item_sk = i_item_sk and + ss_store_sk = s_store_sk and + ss_cdemo_sk = cd_demo_sk and + cd_gender = 'F' and + cd_marital_status = 'U' and + cd_education_status = '2 yr Degree' and + d_year = 2000 and + s_state in ('AL','IN', 'SC', 'NY', 'OH', 'FL') + group by rollup (item.i_item_id, store.s_state) + order by item.i_item_id + ,store.s_state + limit 100; + +-- end query 1 in stream 0 using template query27.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q28.sql b/ydb/library/benchmarks/queries/tpcds/yql/q28.sql new file mode 100644 index 000000000000..df33d66545e5 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q28.sql @@ -0,0 +1,56 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query28.tpl and seed 444293455 +select * +from (select avg(ss_list_price) B1_LP + ,count(ss_list_price) B1_CNT + ,count(distinct ss_list_price) B1_CNTD + from {{store_sales}} as store_sales + where ss_quantity between 0 and 5 + and (ss_list_price between 73 and 73+10 + or ss_coupon_amt between 7826 and 7826+1000 + or ss_wholesale_cost between 70 and 70+20)) B1 cross join + (select avg(ss_list_price) B2_LP + ,count(ss_list_price) B2_CNT + ,count(distinct ss_list_price) B2_CNTD + from {{store_sales}} as store_sales + where ss_quantity between 6 and 10 + and (ss_list_price between 152 and 152+10 + or ss_coupon_amt between 2196 and 2196+1000 + or ss_wholesale_cost between 56 and 56+20)) B2 cross join + (select avg(ss_list_price) B3_LP + ,count(ss_list_price) B3_CNT + ,count(distinct ss_list_price) B3_CNTD + from {{store_sales}} as store_sales + where ss_quantity between 11 and 15 + and (ss_list_price between 53 and 53+10 + or ss_coupon_amt between 3430 and 3430+1000 + or ss_wholesale_cost between 13 and 13+20)) B3 cross join + (select avg(ss_list_price) B4_LP + ,count(ss_list_price) B4_CNT + ,count(distinct ss_list_price) B4_CNTD + from {{store_sales}} as store_sales + where ss_quantity between 16 and 20 + and (ss_list_price between 182 and 182+10 + or ss_coupon_amt between 3262 and 3262+1000 + or ss_wholesale_cost between 20 and 20+20)) B4 cross join + (select avg(ss_list_price) B5_LP + ,count(ss_list_price) B5_CNT + ,count(distinct ss_list_price) B5_CNTD + from {{store_sales}} as store_sales + where ss_quantity between 21 and 25 + and (ss_list_price between 85 and 85+10 + or ss_coupon_amt between 3310 and 3310+1000 + or ss_wholesale_cost between 37 and 37+20)) B5 cross join + (select avg(ss_list_price) B6_LP + ,count(ss_list_price) B6_CNT + ,count(distinct ss_list_price) B6_CNTD + from {{store_sales}} as store_sales + where ss_quantity between 26 and 30 + and (ss_list_price between 180 and 180+10 + or ss_coupon_amt between 12592 and 12592+1000 + or ss_wholesale_cost between 22 and 22+20)) B6 +limit 100; + +-- end query 1 in stream 0 using template query28.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q29.sql b/ydb/library/benchmarks/queries/tpcds/yql/q29.sql new file mode 100644 index 000000000000..50bad554043f --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q29.sql @@ -0,0 +1,50 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query29.tpl and seed 2031708268 +select + item.i_item_id + ,item.i_item_desc + ,store.s_store_id + ,store.s_store_name + ,stddev_samp(ss_quantity) as store_sales_quantity + ,stddev_samp(sr_return_quantity) as store_returns_quantity + ,stddev_samp(cs_quantity) as catalog_sales_quantity + from + {{store_sales}} as store_sales + cross join {{store_returns}} as store_returns + cross join {{catalog_sales}} as catalog_sales + cross join {{date_dim}} d1 + cross join {{date_dim}} d2 + cross join {{date_dim}} d3 + cross join {{store}} as store + cross join {{item}} as item + where + d1.d_moy = 4 + and d1.d_year = 1998 + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and ss_customer_sk = sr_customer_sk + and ss_item_sk = sr_item_sk + and ss_ticket_number = sr_ticket_number + and sr_returned_date_sk = d2.d_date_sk + and d2.d_moy between 4 and 4 + 3 + and d2.d_year = 1998 + and sr_customer_sk = cs_bill_customer_sk + and sr_item_sk = cs_item_sk + and cs_sold_date_sk = d3.d_date_sk + and d3.d_year in (1998,1998+1,1998+2) + group by + item.i_item_id + ,item.i_item_desc + ,store.s_store_id + ,store.s_store_name + order by + item.i_item_id + ,item.i_item_desc + ,store.s_store_id + ,store.s_store_name + limit 100; + +-- end query 1 in stream 0 using template query29.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q30.sql b/ydb/library/benchmarks/queries/tpcds/yql/q30.sql new file mode 100644 index 000000000000..1f987e7dcab1 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q30.sql @@ -0,0 +1,39 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$customer_total_return = + (select web_returns.wr_returning_customer_sk as ctr_customer_sk + ,customer_address.ca_state as ctr_state, + sum(wr_return_amt) as ctr_total_return + from {{web_returns}} as web_returns + cross join {{date_dim}} as date_dim + cross join {{customer_address}} as customer_address + where wr_returned_date_sk = d_date_sk + and d_year =2000 + and wr_returning_addr_sk = ca_address_sk + group by web_returns.wr_returning_customer_sk + ,customer_address.ca_state); + +$avg_total_return_by_state = + (select ctr_state, avg(ctr_total_return) avg_return + from $customer_total_return + group by ctr_state); + +-- start query 1 in stream 0 using template query30.tpl and seed 1819994127 + select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag + ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address + ,c_last_review_date,ctr_total_return + from $customer_total_return ctr1 + join $avg_total_return_by_state ctr2 on ctr1.ctr_state = ctr2.ctr_state + cross join {{customer_address}} as customer_address + cross join {{customer}} as customer + where ctr1.ctr_total_return > 1.2*ctr2.avg_return + and ca_address_sk = c_current_addr_sk + and ca_state = 'GA' + and ctr1.ctr_customer_sk = c_customer_sk + order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag + ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address + ,c_last_review_date,ctr_total_return +limit 100; + +-- end query 1 in stream 0 using template query30.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q31.sql b/ydb/library/benchmarks/queries/tpcds/yql/q31.sql new file mode 100644 index 000000000000..f01fef4094f9 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q31.sql @@ -0,0 +1,61 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$ss = + (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 + from {{store_sales}} as store_sales + cross join {{date_dim}} as date_dim + cross join {{customer_address}} as customer_address + where ss_sold_date_sk = d_date_sk + and ss_addr_sk=ca_address_sk + group by customer_address.ca_county,date_dim.d_qoy, date_dim.d_year); + +$ws = + (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 + from {{web_sales}} as web_sales + cross join {{date_dim}} as date_dim + cross join {{customer_address}} as customer_address + where ws_sold_date_sk = d_date_sk + and ws_bill_addr_sk=ca_address_sk + group by customer_address.ca_county,date_dim.d_qoy, date_dim.d_year); + +-- start query 1 in stream 0 using template query31.tpl and seed 1819994127 + select + ss1.ca_county + ,ss1.d_year + ,ws2.web_sales/ws1.web_sales web_q1_q2_increase + ,ss2.store_sales/ss1.store_sales store_q1_q2_increase + ,ws3.web_sales/ws2.web_sales web_q2_q3_increase + ,ss3.store_sales/ss2.store_sales store_q2_q3_increase + from + $ss ss1 + cross join $ss ss2 + cross join $ss ss3 + cross join $ws ws1 + cross join $ws ws2 + cross join $ws ws3 + where + ss1.d_qoy = 1 + and ss1.d_year = 1999 + and ss1.ca_county = ss2.ca_county + and ss2.d_qoy = 2 + and ss2.d_year = 1999 + and ss2.ca_county = ss3.ca_county + and ss3.d_qoy = 3 + and ss3.d_year = 1999 + and ss1.ca_county = ws1.ca_county + and ws1.d_qoy = 1 + and ws1.d_year = 1999 + and ws1.ca_county = ws2.ca_county + and ws2.d_qoy = 2 + and ws2.d_year = 1999 + and ws1.ca_county = ws3.ca_county + and ws3.d_qoy = 3 + and ws3.d_year =1999 + and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end + > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end + and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end + > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end + order by ss1.d_year; + +-- end query 1 in stream 0 using template query31.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q32.sql b/ydb/library/benchmarks/queries/tpcds/yql/q32.sql new file mode 100644 index 000000000000..d80ad5e371ce --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q32.sql @@ -0,0 +1,35 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$avg_discount_by_item = ( + select + item.i_item_sk i_item_sk, + avg(cs_ext_discount_amt) as avg_discout + from + {{catalog_sales}} as catalog_sales + cross join {{date_dim}} as date_dim + cross join {{item}} as item + where cast (d_date as date) between cast('2002-03-29' as date) and + (cast('2002-03-29' as date) + DateTime::IntervalFromDays(90)) + and d_date_sk = cs_sold_date_sk + group by item.i_item_sk + ); + +-- start query 1 in stream 0 using template query32.tpl and seed 2031708268 +select sum(cs_ext_discount_amt) as `excess discount amount` +from + {{catalog_sales}} cs + cross join {{item}} as item + cross join {{date_dim}} as date_dim + join $avg_discount_by_item adi on cs.cs_item_sk = adi.i_item_sk +where +i_manufact_id = 66 +and item.i_item_sk = cs.cs_item_sk +and cast (d_date as date) between cast('2002-03-29' as date) and + (cast('2002-03-29' as date) + DateTime::IntervalFromDays(90)) +and d_date_sk = cs_sold_date_sk +and cs_ext_discount_amt + > 1.3 * adi.avg_discout +limit 100; + +-- end query 1 in stream 0 using template query32.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q33.sql b/ydb/library/benchmarks/queries/tpcds/yql/q33.sql new file mode 100644 index 000000000000..06e0761b6ff4 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q33.sql @@ -0,0 +1,82 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$ss = ( + select + item.i_manufact_id i_manufact_id,sum(ss_ext_sales_price) total_sales + from + {{store_sales}} as store_sales cross join + {{date_dim}} as date_dim cross join + {{customer_address}} as customer_address cross join + {{item}} as item + where + item.i_manufact_id in (select + i_manufact_id +from + {{item}} as item +where i_category in ('Home')) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 5 + and ss_addr_sk = ca_address_sk + and ca_gmt_offset = -6 + group by item.i_manufact_id); + +$cs = ( + select + item.i_manufact_id i_manufact_id,sum(cs_ext_sales_price) total_sales + from + {{catalog_sales}} as catalog_sales cross join + {{date_dim}} as date_dim cross join + {{customer_address}} as customer_address cross join + {{item}} as item + where + item.i_manufact_id in (select + i_manufact_id +from + {{item}} as item +where i_category in ('Home')) + and cs_item_sk = i_item_sk + and cs_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 5 + and cs_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -6 + group by item.i_manufact_id); + +$ws = ( + select + item.i_manufact_id i_manufact_id,sum(ws_ext_sales_price) total_sales + from + {{web_sales}} as web_sales cross join + {{date_dim}} as date_dim cross join + {{customer_address}} as customer_address cross join + {{item}} as item + where + item.i_manufact_id in (select + i_manufact_id +from + {{item}} as item +where i_category in ('Home')) + and ws_item_sk = i_item_sk + and ws_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 5 + and ws_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -6 + group by item.i_manufact_id); + + +-- start query 1 in stream 0 using template query33.tpl and seed 1930872976 +select i_manufact_id ,sum(total_sales) total_sales + from (select * from $ss + union all + select * from $cs + union all + select * from $ws) tmp1 + group by i_manufact_id + order by total_sales +limit 100; + +-- end query 1 in stream 0 using template query33.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q34.sql b/ydb/library/benchmarks/queries/tpcds/yql/q34.sql new file mode 100644 index 000000000000..4ebe35f56b28 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q34.sql @@ -0,0 +1,38 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query34.tpl and seed 1971067816 +select c_last_name + ,c_first_name + ,c_salutation + ,c_preferred_cust_flag + ,ss_ticket_number + ,cnt from + (select store_sales.ss_ticket_number ss_ticket_number + ,store_sales.ss_customer_sk ss_customer_sk + ,count(*) cnt + from {{store_sales}} as store_sales + cross join {{date_dim}} as date_dim + cross join {{store}} as store + cross join {{household_demographics}} as household_demographics + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) + and (household_demographics.hd_buy_potential = '>10000' or + household_demographics.hd_buy_potential = 'Unknown') + and household_demographics.hd_vehicle_count > 0 + and (case when household_demographics.hd_vehicle_count > 0 + then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count + else null + end) > 1.2 + and date_dim.d_year in (2000,2000+1,2000+2) + and store.s_county in ('Salem County','Terrell County','Arthur County','Oglethorpe County', + 'Lunenburg County','Perry County','Halifax County','Sumner County') + group by store_sales.ss_ticket_number,store_sales.ss_customer_sk) dn + cross join {{customer}} as customer + where ss_customer_sk = c_customer_sk + and cnt between 15 and 20 + order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number; + +-- end query 1 in stream 0 using template query34.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q35.sql b/ydb/library/benchmarks/queries/tpcds/yql/q35.sql new file mode 100644 index 000000000000..59b58cf4ce16 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q35.sql @@ -0,0 +1,69 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$bla1 = (select ss_customer_sk customer_sk + from {{store_sales}} as store_sales + cross join {{date_dim}} as date_dim + where ss_sold_date_sk = d_date_sk and + d_year = 2001 and + d_qoy < 4); +$bla2 = ( + (select ws_bill_customer_sk customer_sk + from {{web_sales}} as web_sales + cross join {{date_dim}} as date_dim + where ws_sold_date_sk = d_date_sk and + d_year = 2001 and + d_qoy < 4) + union all + (select cs_ship_customer_sk customer_sk + from {{catalog_sales}} as catalog_sales + cross join {{date_dim}} as date_dim + where cs_sold_date_sk = d_date_sk and + d_year = 2001 and + d_qoy < 4) +); + +-- start query 1 in stream 0 using template query35.tpl and seed 1930872976 +select + ca.ca_state, + customer_demographics.cd_gender, + customer_demographics.cd_marital_status, + customer_demographics.cd_dep_count, + count(*) cnt1, + avg(customer_demographics.cd_dep_count), + min(customer_demographics.cd_dep_count), + stddev_samp(customer_demographics.cd_dep_count), + customer_demographics.cd_dep_employed_count, + count(*) cnt2, + avg(customer_demographics.cd_dep_employed_count), + min(customer_demographics.cd_dep_employed_count), + stddev_samp(cd_dep_employed_count), + customer_demographics.cd_dep_college_count, + count(*) cnt3, + avg(customer_demographics.cd_dep_college_count), + min(customer_demographics.cd_dep_college_count), + stddev_samp(customer_demographics.cd_dep_college_count) + from + {{customer}} c + cross join {{customer_address}} ca + cross join {{customer_demographics}} as customer_demographics + left semi join $bla1 bla1 on c.c_customer_sk = bla1.customer_sk + left semi join $bla2 bla2 on c.c_customer_sk = bla2.customer_sk + where + c.c_current_addr_sk = ca.ca_address_sk and + cd_demo_sk = c.c_current_cdemo_sk +group by ca.ca_state, + customer_demographics.cd_gender, + customer_demographics.cd_marital_status, + customer_demographics.cd_dep_count, + customer_demographics.cd_dep_employed_count, + customer_demographics.cd_dep_college_count + order by ca.ca_state, + customer_demographics.cd_gender, + customer_demographics.cd_marital_status, + customer_demographics.cd_dep_count, + customer_demographics.cd_dep_employed_count, + customer_demographics.cd_dep_college_count + limit 100; + +-- end query 1 in stream 0 using template query35.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q36.sql b/ydb/library/benchmarks/queries/tpcds/yql/q36.sql new file mode 100644 index 000000000000..514c7fb19fbc --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q36.sql @@ -0,0 +1,33 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query36.tpl and seed 1544728811 +select + sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin + ,item.i_category + ,item.i_class + ,grouping(item.i_category)+grouping(item.i_class) as lochierarchy + ,rank() over ( + partition by grouping(item.i_category)+grouping(item.i_class), + case when grouping(item.i_class) = 0 then item.i_category else null end + order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent + from + {{store_sales}} as store_sales + cross join {{date_dim}} d1 + cross join {{item}} as item + cross join {{store}} as store + where + d1.d_year = 1999 + and d1.d_date_sk = ss_sold_date_sk + and item.i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and s_state in ('IN','AL','MI','MN', + 'TN','LA','FL','NM') + group by rollup(item.i_category,item.i_class) + order by + lochierarchy desc + ,case when lochierarchy = 0 then item.i_category else null end + ,rank_within_parent + limit 100; + +-- end query 1 in stream 0 using template query36.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q37.sql b/ydb/library/benchmarks/queries/tpcds/yql/q37.sql new file mode 100644 index 000000000000..060bf5fc4db2 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q37.sql @@ -0,0 +1,23 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query37.tpl and seed 301843662 +select item.i_item_id + ,item.i_item_desc + ,item.i_current_price + from {{item}} as item + cross join {{inventory}} as inventory + cross join {{date_dim}} as date_dim + cross join {{catalog_sales}} as catalog_sales + where i_current_price between 39 and 39 + 30 + and inv_item_sk = i_item_sk + and d_date_sk=inv_date_sk + and cast(d_date as date) between cast('2001-01-16' as date) and (cast('2001-01-16' as date) + DateTime::IntervalFromDays(60)) + and i_manufact_id in (765,886,889,728) + and inv_quantity_on_hand between 100 and 500 + and cs_item_sk = i_item_sk + group by item.i_item_id,item.i_item_desc,item.i_current_price + order by item.i_item_id + limit 100; + +-- end query 1 in stream 0 using template query37.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q38.sql b/ydb/library/benchmarks/queries/tpcds/yql/q38.sql new file mode 100644 index 000000000000..8814d2291f47 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q38.sql @@ -0,0 +1,35 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$bla1 = (select distinct c_last_name, c_first_name, d_date + from {{store_sales}} as store_sales + cross join {{date_dim}} as date_dim + cross join {{customer}} as customer + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_customer_sk = customer.c_customer_sk + and d_month_seq between 1186 and 1186 + 11); + +$bla2 = (select distinct c_last_name, c_first_name, d_date + from {{catalog_sales}} as catalog_sales + cross join {{date_dim}} as date_dim + cross join {{customer}} as customer + where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk + and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk + and d_month_seq between 1186 and 1186 + 11); + +$bla3 = (select distinct c_last_name, c_first_name, d_date + from {{web_sales}} as web_sales + cross join {{date_dim}} as date_dim + cross join {{customer}} as customer + where web_sales.ws_sold_date_sk = date_dim.d_date_sk + and web_sales.ws_bill_customer_sk = customer.c_customer_sk + and d_month_seq between 1186 and 1186 + 11); + +-- start query 1 in stream 0 using template query38.tpl and seed 1819994127 +select count(*) from ( select * from + $bla1 bla1 join $bla2 bla2 on bla1.c_last_name = bla2.c_last_name and bla1.c_first_name = bla2.c_first_name and bla1.d_date = bla2.d_date + join $bla3 bla3 on bla1.c_last_name = bla3.c_last_name and bla1.c_first_name = bla3.c_first_name and bla1.d_date = bla3.d_date +) hot_cust +limit 100; + +-- end query 1 in stream 0 using template query38.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q39.sql b/ydb/library/benchmarks/queries/tpcds/yql/q39.sql new file mode 100644 index 000000000000..ef676ff40767 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q39.sql @@ -0,0 +1,44 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$inv = +(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy + ,stdev,mean, case mean when 0 then null else stdev/mean end cov + from(select warehouse.w_warehouse_name w_warehouse_name,warehouse.w_warehouse_sk w_warehouse_sk,item.i_item_sk i_item_sk,date_dim.d_moy d_moy + ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean + from {{inventory}} as inverntory + cross join {{item}} as item + cross join {{warehouse}} as warehouse + cross join {{date_dim}} as date_dim + where inv_item_sk = i_item_sk + and inv_warehouse_sk = w_warehouse_sk + and inv_date_sk = d_date_sk + and d_year =2000 + group by warehouse.w_warehouse_name,warehouse.w_warehouse_sk,item.i_item_sk,date_dim.d_moy) foo + where case mean when 0 then 0 else stdev/mean end > 1); + +-- start query 1 in stream 0 using template query39.tpl and seed 1327317894 +select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov + ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov +from $inv inv1 cross join $inv inv2 +where inv1.i_item_sk = inv2.i_item_sk + and inv1.w_warehouse_sk = inv2.w_warehouse_sk + and inv1.d_moy=2 + and inv2.d_moy=2+1 +order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov + ,inv2.d_moy,inv2.mean, inv2.cov +; + +select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov + ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov +from $inv inv1 cross join $inv inv2 +where inv1.i_item_sk = inv2.i_item_sk + and inv1.w_warehouse_sk = inv2.w_warehouse_sk + and inv1.d_moy=2 + and inv2.d_moy=2+1 + and inv1.cov > 1.5 +order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov + ,inv2.d_moy,inv2.mean, inv2.cov +; + +-- end query 1 in stream 0 using template query39.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q40.sql b/ydb/library/benchmarks/queries/tpcds/yql/q40.sql new file mode 100644 index 000000000000..5e4edb0b6f19 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q40.sql @@ -0,0 +1,32 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query40.tpl and seed 1819994127 +select + warehouse.w_state + ,item.i_item_id + ,sum(case when (cast(d_date as date) < cast ('2000-03-18' as date)) + then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before + ,sum(case when (cast(d_date as date) >= cast ('2000-03-18' as date)) + then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after + from + {{catalog_sales}} as catalog_sales + left join {{catalog_returns}} as catalog_returns on + (catalog_sales.cs_order_number = catalog_returns.cr_order_number + and catalog_sales.cs_item_sk = catalog_returns.cr_item_sk) + cross join {{warehouse}} as warehouse + cross join {{item}} as item + cross join {{date_dim}} as date_dim + where + i_current_price between 0.99 and 1.49 + and i_item_sk = cs_item_sk + and cs_warehouse_sk = w_warehouse_sk + and cs_sold_date_sk = d_date_sk + and cast(d_date as date) between (cast ('2000-03-18' as date) - DateTime::IntervalFromDays(30)) + and (cast ('2000-03-18' as date) + DateTime::IntervalFromDays(30)) + group by + warehouse.w_state,item.i_item_id + order by warehouse.w_state,item.i_item_id +limit 100; + +-- end query 1 in stream 0 using template query40.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q41.sql b/ydb/library/benchmarks/queries/tpcds/yql/q41.sql new file mode 100644 index 000000000000..7ecdbf3e6f86 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q41.sql @@ -0,0 +1,58 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$item_cnt_by_manufact = (select i_manufact, count(*) as item_cnt + from {{item}} as item + where ( + ((i_category = 'Women' and + (i_color = 'frosted' or i_color = 'rose') and + (i_units = 'Lb' or i_units = 'Gross') and + (i_size = 'medium' or i_size = 'large') + ) or + (i_category = 'Women' and + (i_color = 'chocolate' or i_color = 'black') and + (i_units = 'Box' or i_units = 'Dram') and + (i_size = 'economy' or i_size = 'petite') + ) or + (i_category = 'Men' and + (i_color = 'slate' or i_color = 'magenta') and + (i_units = 'Carton' or i_units = 'Bundle') and + (i_size = 'N/A' or i_size = 'small') + ) or + (i_category = 'Men' and + (i_color = 'cornflower' or i_color = 'firebrick') and + (i_units = 'Pound' or i_units = 'Oz') and + (i_size = 'medium' or i_size = 'large') + ))) or + ( + ((i_category = 'Women' and + (i_color = 'almond' or i_color = 'steel') and + (i_units = 'Tsp' or i_units = 'Case') and + (i_size = 'medium' or i_size = 'large') + ) or + (i_category = 'Women' and + (i_color = 'purple' or i_color = 'aquamarine') and + (i_units = 'Bunch' or i_units = 'Gram') and + (i_size = 'economy' or i_size = 'petite') + ) or + (i_category = 'Men' and + (i_color = 'lavender' or i_color = 'papaya') and + (i_units = 'Pallet' or i_units = 'Cup') and + (i_size = 'N/A' or i_size = 'small') + ) or + (i_category = 'Men' and + (i_color = 'maroon' or i_color = 'cyan') and + (i_units = 'Each' or i_units = 'N/A') and + (i_size = 'medium' or i_size = 'large') + ))) + group by i_manufact); + +-- start query 1 in stream 0 using template query41.tpl and seed 1581015815 +select distinct(i_product_name) + from {{item}} i1 join $item_cnt_by_manufact i2 using (i_manufact) + where i_manufact_id between 970 and 970+40 + and i2.item_cnt > 0 + order by i_product_name + limit 100; + +-- end query 1 in stream 0 using template query41.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q42.sql b/ydb/library/benchmarks/queries/tpcds/yql/q42.sql new file mode 100644 index 000000000000..c84ed7bf016d --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q42.sql @@ -0,0 +1,25 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query42.tpl and seed 1819994127 +select dt.d_year + ,item.i_category_id + ,item.i_category + ,sum(ss_ext_sales_price) sum_price + from {{date_dim}} dt + cross join {{store_sales}} as store_sales + cross join {{item}} as item + where dt.d_date_sk = store_sales.ss_sold_date_sk + and store_sales.ss_item_sk = item.i_item_sk + and item.i_manager_id = 1 + and dt.d_moy=12 + and dt.d_year=1998 + group by dt.d_year + ,item.i_category_id + ,item.i_category + order by sum_price desc,dt.d_year + ,item.i_category_id + ,item.i_category +limit 100 ; + +-- end query 1 in stream 0 using template query42.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q43.sql b/ydb/library/benchmarks/queries/tpcds/yql/q43.sql new file mode 100644 index 000000000000..4659228c1b7c --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q43.sql @@ -0,0 +1,24 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query43.tpl and seed 1819994127 +select store.s_store_name, store.s_store_id, + sum(case when (d_day_name='Sunday') then ss_sales_price else 0.0 end) sun_sales, + sum(case when (d_day_name='Monday') then ss_sales_price else 0.0 end) mon_sales, + sum(case when (d_day_name='Tuesday') then ss_sales_price else 0.0 end) tue_sales, + sum(case when (d_day_name='Wednesday') then ss_sales_price else 0.0 end) wed_sales, + sum(case when (d_day_name='Thursday') then ss_sales_price else 0.0 end) thu_sales, + sum(case when (d_day_name='Friday') then ss_sales_price else 0.0 end) fri_sales, + sum(case when (d_day_name='Saturday') then ss_sales_price else 0.0 end) sat_sales + from {{date_dim}} as date_dim + cross join {{store_sales}} as store_sales + cross join {{store}} as store + where d_date_sk = ss_sold_date_sk and + s_store_sk = ss_store_sk and + s_gmt_offset = -6 and + d_year = 2001 + group by store.s_store_name, store.s_store_id + order by store.s_store_name, store.s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales + limit 100; + +-- end query 1 in stream 0 using template query43.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q44.sql b/ydb/library/benchmarks/queries/tpcds/yql/q44.sql new file mode 100644 index 000000000000..b08b69879e54 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q44.sql @@ -0,0 +1,38 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$avg_net_profit = (select avg(ss_net_profit) rank_col + from {{store_sales}} as store_sales + where ss_store_sk = 366 + and ss_cdemo_sk is null + group by ss_store_sk); + +-- start query 1 in stream 0 using template query44.tpl and seed 1819994127 +select asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing +from(select * + from (select item_sk,rank() over (order by rank_col asc) rnk + from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col + from {{store_sales}} ss1 + where ss_store_sk = 366 + group by ss_item_sk + having avg(ss_net_profit) > 0.9*$avg_net_profit)V1)V11 + where rnk < 11) asceding + cross join + (select * + from (select item_sk,rank() over (order by rank_col desc) rnk + from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col + from {{store_sales}} ss1 + where ss_store_sk = 366 + group by ss_item_sk + having avg(ss_net_profit) > 0.9*$avg_net_profit)V2)V21 + where rnk < 11) descending + cross join +{{item}} i1 cross join +{{item}} i2 +where asceding.rnk = descending.rnk + and i1.i_item_sk=asceding.item_sk + and i2.i_item_sk=descending.item_sk +order by asceding.rnk +limit 100; + +-- end query 1 in stream 0 using template query44.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q45.sql b/ydb/library/benchmarks/queries/tpcds/yql/q45.sql new file mode 100644 index 000000000000..6fcdcf7ddfdd --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q45.sql @@ -0,0 +1,27 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query45.tpl and seed 2031708268 +select customer_address.ca_zip, customer_address.ca_county, sum(ws_sales_price) + from {{web_sales}} as web_sales + cross join {{customer}} as customer + cross join {{customer_address}} as customer_address + cross join {{date_dim}} as date_dim + cross join {{item}} as item + where ws_bill_customer_sk = c_customer_sk + and c_current_addr_sk = ca_address_sk + and ws_item_sk = i_item_sk + and ( substring(cast(ca_zip as string),1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') + or + i_item_id in (select i_item_id + from {{item}} as item + where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) + ) + ) + and ws_sold_date_sk = d_date_sk + and d_qoy = 1 and d_year = 1998 + group by customer_address.ca_zip, customer_address.ca_county + order by customer_address.ca_zip, customer_address.ca_county + limit 100; + +-- end query 1 in stream 0 using template query45.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q46.sql b/ydb/library/benchmarks/queries/tpcds/yql/q46.sql new file mode 100644 index 000000000000..a9aa06460e42 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q46.sql @@ -0,0 +1,44 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query46.tpl and seed 803547492 +select c_last_name + ,c_first_name + ,ca_city + ,bought_city + ,ss_ticket_number + ,amt,profit + from + (select store_sales.ss_ticket_number ss_ticket_number + ,store_sales.ss_customer_sk ss_customer_sk + ,customer_address.ca_city bought_city + ,sum(ss_coupon_amt) amt + ,sum(ss_net_profit) profit + from {{store_sales}} as store_sales + cross join {{date_dim}} as date_dim + cross join {{store}} as store + cross join {{household_demographics}} as household_demographics + cross join {{customer_address}} as customer_address + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and store_sales.ss_addr_sk = customer_address.ca_address_sk + and (household_demographics.hd_dep_count = 0 or + household_demographics.hd_vehicle_count= 1) + and date_dim.d_dow in (6,0) + and date_dim.d_year in (2000,2000+1,2000+2) + and store.s_city in ('Five Forks','Oakland','Fairview','Winchester','Farmington') + group by store_sales.ss_ticket_number,store_sales.ss_customer_sk,store_sales.ss_addr_sk,customer_address.ca_city) dn + cross join {{customer}} as customer + cross join {{customer_address}} current_addr + where ss_customer_sk = c_customer_sk + and customer.c_current_addr_sk = current_addr.ca_address_sk + and current_addr.ca_city <> bought_city + order by c_last_name + ,c_first_name + ,ca_city + ,bought_city + ,ss_ticket_number + limit 100; + +-- end query 1 in stream 0 using template query46.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q47.sql b/ydb/library/benchmarks/queries/tpcds/yql/q47.sql new file mode 100644 index 000000000000..8da19dcbe00a --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q47.sql @@ -0,0 +1,60 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +$v1 = ( + select item.i_category i_category, item.i_brand i_brand, + store.s_store_name s_store_name, store.s_company_name s_company_name, + date_dim.d_year d_year, date_dim.d_moy d_moy, + sum(ss_sales_price) sum_sales, + avg(sum(ss_sales_price)) over + (partition by item.i_category, item.i_brand, + store.s_store_name, store.s_company_name, date_dim.d_year) + avg_monthly_sales, + rank() over + (partition by item.i_category, item.i_brand, + store.s_store_name, store.s_company_name + order by date_dim.d_year, date_dim.d_moy) rn + from {{item}} as item + cross join {{store_sales}} as store_sales + cross join {{date_dim}} as date_dim + cross join {{store}} as store + where ss_item_sk = i_item_sk and + ss_sold_date_sk = d_date_sk and + ss_store_sk = s_store_sk and + ( + d_year = 1999 or + ( d_year = 1999-1 and d_moy =12) or + ( d_year = 1999+1 and d_moy =1) + ) + group by item.i_category, item.i_brand, + store.s_store_name, store.s_company_name, + date_dim.d_year, date_dim.d_moy); + +$v2 = ( + select v1.s_store_name s_store_name + ,v1.d_year d_year, v1.d_moy d_moy + ,v1.avg_monthly_sales avg_monthly_sales + ,v1.sum_sales sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum + from $v1 v1 cross join $v1 v1_lag cross join $v1 v1_lead + where v1.i_category = v1_lag.i_category and + v1.i_category = v1_lead.i_category and + v1.i_brand = v1_lag.i_brand and + v1.i_brand = v1_lead.i_brand and + v1.s_store_name = v1_lag.s_store_name and + v1.s_store_name = v1_lead.s_store_name and + v1.s_company_name = v1_lag.s_company_name and + v1.s_company_name = v1_lead.s_company_name and + v1.rn = v1_lag.rn + 1 and + v1.rn = v1_lead.rn - 1); + + +-- start query 1 in stream 0 using template query47.tpl and seed 2031708268 +select * + from $v2 + where d_year = 1999 and + avg_monthly_sales > 0 and + case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 + order by sum_sales - avg_monthly_sales, sum_sales + limit 100; + +-- end query 1 in stream 0 using template query47.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q48.sql b/ydb/library/benchmarks/queries/tpcds/yql/q48.sql new file mode 100644 index 000000000000..e832c616a230 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q48.sql @@ -0,0 +1,74 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query48.tpl and seed 622697896 +select sum (ss_quantity) + from {{store_sales}} as store_sales + cross join {{store}} as store + cross join {{customer_demographics}} as customer_demographics + cross join {{customer_address}} as customer_address + cross join {{date_dim}} as date_dim + where s_store_sk = ss_store_sk + and ss_sold_date_sk = d_date_sk and d_year = 1998 + and + ( + ( + cd_demo_sk = ss_cdemo_sk + and + cd_marital_status = 'M' + and + cd_education_status = 'Unknown' + and + ss_sales_price between 100.00 and 150.00 + ) + or + ( + cd_demo_sk = ss_cdemo_sk + and + cd_marital_status = 'W' + and + cd_education_status = 'College' + and + ss_sales_price between 50.00 and 100.00 + ) + or + ( + cd_demo_sk = ss_cdemo_sk + and + cd_marital_status = 'D' + and + cd_education_status = 'Primary' + and + ss_sales_price between 150.00 and 200.00 + ) + ) + and + ( + ( + ss_addr_sk = ca_address_sk + and + ca_country = 'United States' + and + ca_state in ('MI', 'GA', 'NH') + and ss_net_profit between 0 and 2000 + ) + or + (ss_addr_sk = ca_address_sk + and + ca_country = 'United States' + and + ca_state in ('TX', 'KY', 'SD') + and ss_net_profit between 150 and 3000 + ) + or + (ss_addr_sk = ca_address_sk + and + ca_country = 'United States' + and + ca_state in ('NY', 'OH', 'FL') + and ss_net_profit between 50 and 25000 + ) + ) +; + +-- end query 1 in stream 0 using template query48.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q49.sql b/ydb/library/benchmarks/queries/tpcds/yql/q49.sql new file mode 100644 index 000000000000..daa3a2a097dc --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q49.sql @@ -0,0 +1,144 @@ +{% include 'header.sql.jinja' %} + +-- NB: Subquerys +-- start query 1 in stream 0 using template query49.tpl and seed 1819994127 +$non_unique = (select channel, item, return_ratio, return_rank, currency_rank from + (select + 'web' as channel + ,web.item as item + ,web.return_ratio as return_ratio + ,web.return_rank as return_rank + ,web.currency_rank as currency_rank + from ( + select + item + ,return_ratio + ,currency_ratio + ,rank() over (order by return_ratio) as return_rank + ,rank() over (order by currency_ratio) as currency_rank + from + ( select ws.ws_item_sk as item + ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as float)/ + cast(sum(coalesce(ws.ws_quantity,0)) as float )) as return_ratio + ,(cast(sum(coalesce(wr.wr_return_amt,0)) as float)/ + cast(sum(coalesce(ws.ws_net_paid,0)) as float )) as currency_ratio + from + {{web_sales}} ws + left join {{web_returns}} wr + on (ws.ws_order_number = wr.wr_order_number and + ws.ws_item_sk = wr.wr_item_sk) + cross join {{date_dim}} as date_dim + where + wr.wr_return_amt > 10000 + and ws.ws_net_profit > 1 + and ws.ws_net_paid > 0 + and ws.ws_quantity > 0 + and ws_sold_date_sk = d_date_sk + and d_year = 2000 + and d_moy = 12 + group by ws.ws_item_sk + ) in_web + ) web + where + ( + web.return_rank <= 10 + or + web.currency_rank <= 10 + ) + union all + select + 'catalog' as channel + ,catalog.item as item + ,catalog.return_ratio as return_ratio + ,catalog.return_rank as return_rank + ,catalog.currency_rank as currency_rank + from ( + select + item + ,return_ratio + ,currency_ratio + ,rank() over (order by return_ratio) as return_rank + ,rank() over (order by currency_ratio) as currency_rank + from + ( select + cs.cs_item_sk as item + ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as float)/ + cast(sum(coalesce(cs.cs_quantity,0)) as float)) as return_ratio + ,(cast(sum(coalesce(cr.cr_return_amount,0)) as float)/ + cast(sum(coalesce(cs.cs_net_paid,0)) as float )) as currency_ratio + from + {{catalog_sales}} cs + left outer join {{catalog_returns}} cr + on (cs.cs_order_number = cr.cr_order_number and + cs.cs_item_sk = cr.cr_item_sk) + cross join {{date_dim}} as date_dim + where + cr.cr_return_amount > 10000 + and cs.cs_net_profit > 1 + and cs.cs_net_paid > 0 + and cs.cs_quantity > 0 + and cs_sold_date_sk = d_date_sk + and d_year = 2000 + and d_moy = 12 + group by cs.cs_item_sk + ) in_cat + ) catalog + where + ( + catalog.return_rank <= 10 + or + catalog.currency_rank <=10 + ) + union all + select + 'store' as channel + ,store.item as item + ,store.return_ratio as return_ratio + ,store.return_rank as return_rank + ,store.currency_rank as currency_rank + from ( + select + item + ,return_ratio + ,currency_ratio + ,rank() over (order by return_ratio) as return_rank + ,rank() over (order by currency_ratio) as currency_rank + from + ( select sts.ss_item_sk as item + ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as float)/cast(sum(coalesce(sts.ss_quantity,0)) as float )) as return_ratio + ,(cast(sum(coalesce(sr.sr_return_amt,0)) as float)/cast(sum(coalesce(sts.ss_net_paid,0)) as float)) as currency_ratio + from + {{store_sales}} sts + left outer join {{store_returns}} sr + on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) + cross join {{date_dim}} as date_dim + where + sr.sr_return_amt > 10000 + and sts.ss_net_profit > 1 + and sts.ss_net_paid > 0 + and sts.ss_quantity > 0 + and ss_sold_date_sk = d_date_sk + and d_year = 2000 + and d_moy = 12 + group by sts.ss_item_sk + ) in_store + ) store + where ( + store.return_rank <= 10 + or + store.currency_rank <= 10 + ) + ) y); + +select DISTINCT * + from $non_unique + order by channel,return_rank,currency_rank,item + limit 100; + +-- 'store' as channel +-- ,store.item as item +-- ,store.return_ratio as return_ratio +-- ,store.return_rank as return_rank +-- ,store.currency_rank as currency_rank + +-- end query 1 in stream 0 using template query49.tpl diff --git a/ydb/library/benchmarks/queries/tpcds/yql/q50.sql b/ydb/library/benchmarks/queries/tpcds/yql/q50.sql new file mode 100644 index 000000000000..e6e92fa08010 --- /dev/null +++ b/ydb/library/benchmarks/queries/tpcds/yql/q50.sql @@ -0,0 +1,66 @@ +{% include 'header.sql.jinja' %} + +-- start query 1 in stream 0 using template query50.tpl and seed 1819994127 +select + store.s_store_name + ,store.s_company_id + ,store.s_street_number + ,store.s_street_name + ,store.s_street_type + ,store.s_suite_number + ,store.s_city + ,store.s_county + ,store.s_state + ,store.s_zip + ,sum(case when (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk <= 30 ) then 1 else 0 end) as `30 days` + ,sum(case when (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk > 30) and + (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk <= 60) then 1 else 0 end ) as `31-60 days` + ,sum(case when (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk > 60) and + (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk <= 90) then 1 else 0 end) as `61-90 days` + ,sum(case when (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk > 90) and + (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk <= 120) then 1 else 0 end) as `91-120 days` + ,sum(case when (store_returns.sr_returned_date_sk - store_sales.ss_sold_date_sk > 120) then 1 else 0 end) as `>120 days` +from + {{store_sales}} as store_sales +cross join + {{store_returns}} as store_returns +cross join + {{store}} as store +cross join + {{date_dim}} as d1 +cross join + {{date_dim}} as d2 +where + d2.d_year = 1998 +and d2.d_moy = 9 +and ss_ticket_number = sr_ticket_number +and ss_item_sk = sr_item_sk +and ss_sold_date_sk = d1.d_date_sk +and sr_returned_date_sk = d2.d_date_sk +and ss_customer_sk = sr_customer_sk +and ss_store_sk = s_store_sk +group by + store.s_store_name + ,store.s_company_id + ,store.s_street_number + ,store.s_street_name + ,store.s_street_type + ,store.s_suite_number + ,store.s_city + ,store.s_county + ,store.s_state + ,store.s_zip +order by s_store_name + ,s_company_id + ,s_street_number + ,s_street_name + ,s_street_type + ,s_suite_number + ,s_city + ,s_county + ,s_state + ,s_zip +limit 100; + +-- end query 1 in stream 0 using template query50.tpl +;