|
| 1 | +-- SQLBench-DS query 11 derived from TPC-DS query 11 under the terms of the TPC Fair Use Policy. |
| 2 | +-- TPC-DS queries are Copyright 2021 Transaction Processing Performance Council. |
| 3 | +-- This query was generated at scale factor 1. |
| 4 | +with year_total as ( |
| 5 | + select c_customer_id customer_id |
| 6 | + ,c_first_name customer_first_name |
| 7 | + ,c_last_name customer_last_name |
| 8 | + ,c_preferred_cust_flag customer_preferred_cust_flag |
| 9 | + ,c_birth_country customer_birth_country |
| 10 | + ,c_login customer_login |
| 11 | + ,c_email_address customer_email_address |
| 12 | + ,d_year dyear |
| 13 | + ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total |
| 14 | + ,'s' sale_type |
| 15 | + from customer |
| 16 | + ,store_sales |
| 17 | + ,date_dim |
| 18 | + where c_customer_sk = ss_customer_sk |
| 19 | + and ss_sold_date_sk = d_date_sk |
| 20 | + group by c_customer_id |
| 21 | + ,c_first_name |
| 22 | + ,c_last_name |
| 23 | + ,c_preferred_cust_flag |
| 24 | + ,c_birth_country |
| 25 | + ,c_login |
| 26 | + ,c_email_address |
| 27 | + ,d_year |
| 28 | + union all |
| 29 | + select c_customer_id customer_id |
| 30 | + ,c_first_name customer_first_name |
| 31 | + ,c_last_name customer_last_name |
| 32 | + ,c_preferred_cust_flag customer_preferred_cust_flag |
| 33 | + ,c_birth_country customer_birth_country |
| 34 | + ,c_login customer_login |
| 35 | + ,c_email_address customer_email_address |
| 36 | + ,d_year dyear |
| 37 | + ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total |
| 38 | + ,'w' sale_type |
| 39 | + from customer |
| 40 | + ,web_sales |
| 41 | + ,date_dim |
| 42 | + where c_customer_sk = ws_bill_customer_sk |
| 43 | + and ws_sold_date_sk = d_date_sk |
| 44 | + group by c_customer_id |
| 45 | + ,c_first_name |
| 46 | + ,c_last_name |
| 47 | + ,c_preferred_cust_flag |
| 48 | + ,c_birth_country |
| 49 | + ,c_login |
| 50 | + ,c_email_address |
| 51 | + ,d_year |
| 52 | + ) |
| 53 | + select |
| 54 | + t_s_secyear.customer_id |
| 55 | + ,t_s_secyear.customer_first_name |
| 56 | + ,t_s_secyear.customer_last_name |
| 57 | + ,t_s_secyear.customer_email_address |
| 58 | + from year_total t_s_firstyear |
| 59 | + ,year_total t_s_secyear |
| 60 | + ,year_total t_w_firstyear |
| 61 | + ,year_total t_w_secyear |
| 62 | + where t_s_secyear.customer_id = t_s_firstyear.customer_id |
| 63 | + and t_s_firstyear.customer_id = t_w_secyear.customer_id |
| 64 | + and t_s_firstyear.customer_id = t_w_firstyear.customer_id |
| 65 | + and t_s_firstyear.sale_type = 's' |
| 66 | + and t_w_firstyear.sale_type = 'w' |
| 67 | + and t_s_secyear.sale_type = 's' |
| 68 | + and t_w_secyear.sale_type = 'w' |
| 69 | + and t_s_firstyear.dyear = 1999 |
| 70 | + and t_s_secyear.dyear = 1999+1 |
| 71 | + and t_w_firstyear.dyear = 1999 |
| 72 | + and t_w_secyear.dyear = 1999+1 |
| 73 | + and t_s_firstyear.year_total > 0 |
| 74 | + and t_w_firstyear.year_total > 0 |
| 75 | + and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end |
| 76 | + > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end |
| 77 | + order by t_s_secyear.customer_id |
| 78 | + ,t_s_secyear.customer_first_name |
| 79 | + ,t_s_secyear.customer_last_name |
| 80 | + ,t_s_secyear.customer_email_address |
| 81 | + LIMIT 100; |
| 82 | + |
0 commit comments