aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/pg-tpcds/q49.sql
diff options
context:
space:
mode:
authorudovichenko-r <udovichenko-r@yandex-team.com>2024-11-19 14:58:38 +0300
committerudovichenko-r <udovichenko-r@yandex-team.com>2024-11-19 15:16:27 +0300
commit24521403b1c44303e043ba540c09b1fe991c7474 (patch)
tree341d1e7206bc7c143d04d2d96f05b6dc0655606d /yql/essentials/tests/sql/suites/pg-tpcds/q49.sql
parent72b3cd51dc3fb9d16975d353ea82fd85701393cc (diff)
downloadydb-24521403b1c44303e043ba540c09b1fe991c7474.tar.gz
YQL-19206 Move contrib/ydb/library/yql/tests/sql/suites -> yql/essentials/tests/sql/suites
commit_hash:d0ef1f92b09c94db7c2408f946d2a4c62b603f00
Diffstat (limited to 'yql/essentials/tests/sql/suites/pg-tpcds/q49.sql')
-rw-r--r--yql/essentials/tests/sql/suites/pg-tpcds/q49.sql132
1 files changed, 132 insertions, 0 deletions
diff --git a/yql/essentials/tests/sql/suites/pg-tpcds/q49.sql b/yql/essentials/tests/sql/suites/pg-tpcds/q49.sql
new file mode 100644
index 0000000000..62fa592b2b
--- /dev/null
+++ b/yql/essentials/tests/sql/suites/pg-tpcds/q49.sql
@@ -0,0 +1,132 @@
+--!syntax_pg
+--TPC-DS Q49
+
+-- start query 1 in stream 0 using template ../query_templates/query49.tpl
+select channel, item, return_ratio, return_rank, currency_rank from
+ (select
+ 'web' as channel
+ ,web.item
+ ,web.return_ratio
+ ,web.return_rank
+ ,web.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 decimal(15,4))/
+ cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio
+ ,(cast(sum(coalesce(wr.wr_return_amt,0::numeric)) as decimal(15,4))/
+ cast(sum(coalesce(ws.ws_net_paid,0::numeric)) as decimal(15,4) )) as currency_ratio
+ from
+ plato.web_sales ws left outer join plato.web_returns wr
+ on (ws.ws_order_number = wr.wr_order_number and
+ ws.ws_item_sk = wr.wr_item_sk)
+ ,plato.date_dim
+ where
+ wr.wr_return_amt > 10000::numeric
+ and ws.ws_net_profit > 1::numeric
+ and ws.ws_net_paid > 0::numeric
+ 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
+ select
+ 'catalog' as channel
+ ,catalog.item
+ ,catalog.return_ratio
+ ,catalog.return_rank
+ ,catalog.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 decimal(15,4))/
+ cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio
+ ,(cast(sum(coalesce(cr.cr_return_amount,0::numeric)) as decimal(15,4))/
+ cast(sum(coalesce(cs.cs_net_paid,0::numeric)) as decimal(15,4) )) as currency_ratio
+ from
+ plato.catalog_sales cs left outer join plato.catalog_returns cr
+ on (cs.cs_order_number = cr.cr_order_number and
+ cs.cs_item_sk = cr.cr_item_sk)
+ ,plato.date_dim
+ where
+ cr.cr_return_amount > 10000::numeric
+ and cs.cs_net_profit > 1::numeric
+ and cs.cs_net_paid > 0::numeric
+ 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
+ select
+ 'store' as channel
+ ,store.item
+ ,store.return_ratio
+ ,store.return_rank
+ ,store.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 decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio
+ ,(cast(sum(coalesce(sr.sr_return_amt,0::numeric)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0::numeric)) as decimal(15,4) )) as currency_ratio
+ from
+ plato.store_sales sts left outer join plato.store_returns sr
+ on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk)
+ ,plato.date_dim
+ where
+ sr.sr_return_amt > 10000::numeric
+ and sts.ss_net_profit > 1::numeric
+ and sts.ss_net_paid > 0::numeric
+ 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
+ )
+ ) a
+ order by 1,4,5,2
+ limit 100;
+
+-- end query 1 in stream 0 using template ../query_templates/query49.tpl