github.com/dolthub/go-mysql-server@v0.18.0/enginetest/queries/tpc_ds_plans.go (about) 1 package queries 2 3 var TpcdsPlanTests = []QueryPlanTest{ 4 { 5 Query: ` 6 -- start query 1 in stream 0 using template query1.tpl 7 with customer_total_return as 8 (select sr_customer_sk as ctr_customer_sk 9 ,sr_store_sk as ctr_store_sk 10 ,sum(SR_FEE) as ctr_total_return 11 from store_returns 12 ,date_dim 13 where sr_returned_date_sk = d_date_sk 14 and d_year =2000 15 group by sr_customer_sk 16 ,sr_store_sk) 17 select c_customer_id 18 from customer_total_return ctr1 19 ,store 20 ,customer 21 where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 22 from customer_total_return ctr2 23 where ctr1.ctr_store_sk = ctr2.ctr_store_sk) 24 and s_store_sk = ctr1.ctr_store_sk 25 and s_state = 'TN' 26 and ctr1.ctr_customer_sk = c_customer_sk 27 order by c_customer_id 28 limit 100;`, 29 }, 30 { 31 Query: ` 32 -- start query 2 in stream 0 using template query2.tpl 33 with wscs as 34 (select sold_date_sk 35 ,sales_price 36 from (select ws_sold_date_sk sold_date_sk 37 ,ws_ext_sales_price sales_price 38 from web_sales 39 union all 40 select cs_sold_date_sk sold_date_sk 41 ,cs_ext_sales_price sales_price 42 from catalog_sales) dt), 43 wswscs as 44 (select d_week_seq, 45 sum(case when (d_day_name='Sunday') then sales_price else null end) sun_sales, 46 sum(case when (d_day_name='Monday') then sales_price else null end) mon_sales, 47 sum(case when (d_day_name='Tuesday') then sales_price else null end) tue_sales, 48 sum(case when (d_day_name='Wednesday') then sales_price else null end) wed_sales, 49 sum(case when (d_day_name='Thursday') then sales_price else null end) thu_sales, 50 sum(case when (d_day_name='Friday') then sales_price else null end) fri_sales, 51 sum(case when (d_day_name='Saturday') then sales_price else null end) sat_sales 52 from wscs 53 ,date_dim 54 where d_date_sk = sold_date_sk 55 group by d_week_seq) 56 select d_week_seq1 57 ,round(sun_sales1/sun_sales2,2) 58 ,round(mon_sales1/mon_sales2,2) 59 ,round(tue_sales1/tue_sales2,2) 60 ,round(wed_sales1/wed_sales2,2) 61 ,round(thu_sales1/thu_sales2,2) 62 ,round(fri_sales1/fri_sales2,2) 63 ,round(sat_sales1/sat_sales2,2) 64 from 65 (select wswscs.d_week_seq d_week_seq1 66 ,sun_sales sun_sales1 67 ,mon_sales mon_sales1 68 ,tue_sales tue_sales1 69 ,wed_sales wed_sales1 70 ,thu_sales thu_sales1 71 ,fri_sales fri_sales1 72 ,sat_sales sat_sales1 73 from wswscs,date_dim 74 where date_dim.d_week_seq = wswscs.d_week_seq and 75 d_year = 1998) y, 76 (select wswscs.d_week_seq d_week_seq2 77 ,sun_sales sun_sales2 78 ,mon_sales mon_sales2 79 ,tue_sales tue_sales2 80 ,wed_sales wed_sales2 81 ,thu_sales thu_sales2 82 ,fri_sales fri_sales2 83 ,sat_sales sat_sales2 84 from wswscs 85 ,date_dim 86 where date_dim.d_week_seq = wswscs.d_week_seq and 87 d_year = 1998+1) z 88 where d_week_seq1=d_week_seq2-53 89 order by d_week_seq1;`, 90 }, 91 { 92 Query: ` 93 -- start query 3 in stream 0 using template query3.tpl 94 select dt.d_year 95 ,item.i_brand_id brand_id 96 ,item.i_brand brand 97 ,sum(ss_sales_price) sum_agg 98 from date_dim dt 99 ,store_sales 100 ,item 101 where dt.d_date_sk = store_sales.ss_sold_date_sk 102 and store_sales.ss_item_sk = item.i_item_sk 103 and item.i_manufact_id = 816 104 and dt.d_moy=11 105 group by dt.d_year 106 ,item.i_brand 107 ,item.i_brand_id 108 order by dt.d_year 109 ,sum_agg desc 110 ,brand_id 111 limit 100;`, 112 }, 113 { 114 Query: ` 115 -- start query 4 in stream 0 using template query4.tpl 116 with year_total as ( 117 select c_customer_id customer_id 118 ,c_first_name customer_first_name 119 ,c_last_name customer_last_name 120 ,c_preferred_cust_flag customer_preferred_cust_flag 121 ,c_birth_country customer_birth_country 122 ,c_login customer_login 123 ,c_email_address customer_email_address 124 ,d_year dyear 125 ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total 126 ,'s' sale_type 127 from customer 128 ,store_sales 129 ,date_dim 130 where c_customer_sk = ss_customer_sk 131 and ss_sold_date_sk = d_date_sk 132 group by c_customer_id 133 ,c_first_name 134 ,c_last_name 135 ,c_preferred_cust_flag 136 ,c_birth_country 137 ,c_login 138 ,c_email_address 139 ,d_year 140 union all 141 select c_customer_id customer_id 142 ,c_first_name customer_first_name 143 ,c_last_name customer_last_name 144 ,c_preferred_cust_flag customer_preferred_cust_flag 145 ,c_birth_country customer_birth_country 146 ,c_login customer_login 147 ,c_email_address customer_email_address 148 ,d_year dyear 149 ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total 150 ,'c' sale_type 151 from customer 152 ,catalog_sales 153 ,date_dim 154 where c_customer_sk = cs_bill_customer_sk 155 and cs_sold_date_sk = d_date_sk 156 group by c_customer_id 157 ,c_first_name 158 ,c_last_name 159 ,c_preferred_cust_flag 160 ,c_birth_country 161 ,c_login 162 ,c_email_address 163 ,d_year 164 union all 165 select c_customer_id customer_id 166 ,c_first_name customer_first_name 167 ,c_last_name customer_last_name 168 ,c_preferred_cust_flag customer_preferred_cust_flag 169 ,c_birth_country customer_birth_country 170 ,c_login customer_login 171 ,c_email_address customer_email_address 172 ,d_year dyear 173 ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total 174 ,'w' sale_type 175 from customer 176 ,web_sales 177 ,date_dim 178 where c_customer_sk = ws_bill_customer_sk 179 and ws_sold_date_sk = d_date_sk 180 group by c_customer_id 181 ,c_first_name 182 ,c_last_name 183 ,c_preferred_cust_flag 184 ,c_birth_country 185 ,c_login 186 ,c_email_address 187 ,d_year 188 ) 189 select 190 t_s_secyear.customer_id 191 ,t_s_secyear.customer_first_name 192 ,t_s_secyear.customer_last_name 193 ,t_s_secyear.customer_birth_country 194 from year_total t_s_firstyear 195 ,year_total t_s_secyear 196 ,year_total t_c_firstyear 197 ,year_total t_c_secyear 198 ,year_total t_w_firstyear 199 ,year_total t_w_secyear 200 where t_s_secyear.customer_id = t_s_firstyear.customer_id 201 and t_s_firstyear.customer_id = t_c_secyear.customer_id 202 and t_s_firstyear.customer_id = t_c_firstyear.customer_id 203 and t_s_firstyear.customer_id = t_w_firstyear.customer_id 204 and t_s_firstyear.customer_id = t_w_secyear.customer_id 205 and t_s_firstyear.sale_type = 's' 206 and t_c_firstyear.sale_type = 'c' 207 and t_w_firstyear.sale_type = 'w' 208 and t_s_secyear.sale_type = 's' 209 and t_c_secyear.sale_type = 'c' 210 and t_w_secyear.sale_type = 'w' 211 and t_s_firstyear.dyear = 1999 212 and t_s_secyear.dyear = 1999+1 213 and t_c_firstyear.dyear = 1999 214 and t_c_secyear.dyear = 1999+1 215 and t_w_firstyear.dyear = 1999 216 and t_w_secyear.dyear = 1999+1 217 and t_s_firstyear.year_total > 0 218 and t_c_firstyear.year_total > 0 219 and t_w_firstyear.year_total > 0 220 and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end 221 > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end 222 and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end 223 > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end 224 order by t_s_secyear.customer_id 225 ,t_s_secyear.customer_first_name 226 ,t_s_secyear.customer_last_name 227 ,t_s_secyear.customer_birth_country 228 limit 100;`, 229 }, 230 { 231 Query: ` 232 -- start query 5 in stream 0 using template query5.tpl 233 with ssr as 234 (select s_store_id, 235 sum(sales_price) as sales, 236 sum(profit) as profit, 237 sum(return_amt) as returns, 238 sum(net_loss) as profit_loss 239 from 240 ( select ss_store_sk as store_sk, 241 ss_sold_date_sk as date_sk, 242 ss_ext_sales_price as sales_price, 243 ss_net_profit as profit, 244 cast(0 as decimal(7,2)) as return_amt, 245 cast(0 as decimal(7,2)) as net_loss 246 from store_sales 247 union all 248 select sr_store_sk as store_sk, 249 sr_returned_date_sk as date_sk, 250 cast(0 as decimal(7,2)) as sales_price, 251 cast(0 as decimal(7,2)) as profit, 252 sr_return_amt as return_amt, 253 sr_net_loss as net_loss 254 from store_returns 255 ) salesreturns, 256 date_dim, 257 store 258 where date_sk = d_date_sk 259 and d_date between cast('2000-08-19' as date) 260 and (cast('2000-08-19' as date) + interval 14 day) 261 and store_sk = s_store_sk 262 group by s_store_id) 263 , 264 csr as 265 (select cp_catalog_page_id, 266 sum(sales_price) as sales, 267 sum(profit) as profit, 268 sum(return_amt) as returns, 269 sum(net_loss) as profit_loss 270 from 271 ( select cs_catalog_page_sk as page_sk, 272 cs_sold_date_sk as date_sk, 273 cs_ext_sales_price as sales_price, 274 cs_net_profit as profit, 275 cast(0 as decimal(7,2)) as return_amt, 276 cast(0 as decimal(7,2)) as net_loss 277 from catalog_sales 278 union all 279 select cr_catalog_page_sk as page_sk, 280 cr_returned_date_sk as date_sk, 281 cast(0 as decimal(7,2)) as sales_price, 282 cast(0 as decimal(7,2)) as profit, 283 cr_return_amount as return_amt, 284 cr_net_loss as net_loss 285 from catalog_returns 286 ) salesreturns, 287 date_dim, 288 catalog_page 289 where date_sk = d_date_sk 290 and d_date between cast('2000-08-19' as date) 291 and (cast('2000-08-19' as date) + interval 14 day) 292 and page_sk = cp_catalog_page_sk 293 group by cp_catalog_page_id) 294 , 295 wsr as 296 (select web_site_id, 297 sum(sales_price) as sales, 298 sum(profit) as profit, 299 sum(return_amt) as returns, 300 sum(net_loss) as profit_loss 301 from 302 ( select ws_web_site_sk as wsr_web_site_sk, 303 ws_sold_date_sk as date_sk, 304 ws_ext_sales_price as sales_price, 305 ws_net_profit as profit, 306 cast(0 as decimal(7,2)) as return_amt, 307 cast(0 as decimal(7,2)) as net_loss 308 from web_sales 309 union all 310 select ws_web_site_sk as wsr_web_site_sk, 311 wr_returned_date_sk as date_sk, 312 cast(0 as decimal(7,2)) as sales_price, 313 cast(0 as decimal(7,2)) as profit, 314 wr_return_amt as return_amt, 315 wr_net_loss as net_loss 316 from web_returns left outer join web_sales on 317 ( wr_item_sk = ws_item_sk 318 and wr_order_number = ws_order_number) 319 ) salesreturns, 320 date_dim, 321 web_site 322 where date_sk = d_date_sk 323 and d_date between cast('2000-08-19' as date) 324 and (cast('2000-08-19' as date) + interval 14 day) 325 and wsr_web_site_sk = web_site_sk 326 group by web_site_id) 327 select channel 328 , id 329 , sum(sales) as sales 330 , sum(returns) as returns 331 , sum(profit) as profit 332 from 333 (select 'store channel' as channel 334 , 'store' || s_store_id as id 335 , sales 336 , returns 337 , (profit - profit_loss) as profit 338 from ssr 339 union all 340 select 'catalog channel' as channel 341 , 'catalog_page' || cp_catalog_page_id as id 342 , sales 343 , returns 344 , (profit - profit_loss) as profit 345 from csr 346 union all 347 select 'web channel' as channel 348 , 'web_site' || web_site_id as id 349 , sales 350 , returns 351 , (profit - profit_loss) as profit 352 from wsr 353 ) x 354 group by rollup (channel, id) 355 order by channel 356 ,id 357 limit 100;`, 358 Skip: true, 359 }, 360 { 361 Query: ` 362 -- start query 6 in stream 0 using template query6.tpl 363 select a.ca_state state, count(*) cnt 364 from customer_address a 365 ,customer c 366 ,store_sales s 367 ,date_dim d 368 ,item i 369 where a.ca_address_sk = c.c_current_addr_sk 370 and c.c_customer_sk = s.ss_customer_sk 371 and s.ss_sold_date_sk = d.d_date_sk 372 and s.ss_item_sk = i.i_item_sk 373 and d.d_month_seq = 374 (select distinct (d_month_seq) 375 from date_dim 376 where d_year = 2002 377 and d_moy = 3 ) 378 and i.i_current_price > 1.2 * 379 (select avg(j.i_current_price) 380 from item j 381 where j.i_category = i.i_category) 382 group by a.ca_state 383 having count(*) >= 10 384 order by cnt, a.ca_state 385 limit 100;`, 386 }, 387 { 388 Query: ` 389 -- start query 7 in stream 0 using template query7.tpl 390 select i_item_id, 391 avg(ss_quantity) agg1, 392 avg(ss_list_price) agg2, 393 avg(ss_coupon_amt) agg3, 394 avg(ss_sales_price) agg4 395 from store_sales, customer_demographics, date_dim, item, promotion 396 where ss_sold_date_sk = d_date_sk and 397 ss_item_sk = i_item_sk and 398 ss_cdemo_sk = cd_demo_sk and 399 ss_promo_sk = p_promo_sk and 400 cd_gender = 'F' and 401 cd_marital_status = 'W' and 402 cd_education_status = 'College' and 403 (p_channel_email = 'N' or p_channel_event = 'N') and 404 d_year = 2001 405 group by i_item_id 406 order by i_item_id 407 limit 100;`, 408 }, 409 { 410 Query: ` 411 -- start query 8 in stream 0 using template query8.tpl 412 select s_store_name 413 ,sum(ss_net_profit) 414 from store_sales 415 ,date_dim 416 ,store, 417 (select ca_zip 418 from ( 419 SELECT substr(ca_zip,1,5) ca_zip 420 FROM customer_address 421 WHERE substr(ca_zip,1,5) IN ( 422 '47602','16704','35863','28577','83910','36201', 423 '58412','48162','28055','41419','80332', 424 '38607','77817','24891','16226','18410', 425 '21231','59345','13918','51089','20317', 426 '17167','54585','67881','78366','47770', 427 '18360','51717','73108','14440','21800', 428 '89338','45859','65501','34948','25973', 429 '73219','25333','17291','10374','18829', 430 '60736','82620','41351','52094','19326', 431 '25214','54207','40936','21814','79077', 432 '25178','75742','77454','30621','89193', 433 '27369','41232','48567','83041','71948', 434 '37119','68341','14073','16891','62878', 435 '49130','19833','24286','27700','40979', 436 '50412','81504','94835','84844','71954', 437 '39503','57649','18434','24987','12350', 438 '86379','27413','44529','98569','16515', 439 '27287','24255','21094','16005','56436', 440 '91110','68293','56455','54558','10298', 441 '83647','32754','27052','51766','19444', 442 '13869','45645','94791','57631','20712', 443 '37788','41807','46507','21727','71836', 444 '81070','50632','88086','63991','20244', 445 '31655','51782','29818','63792','68605', 446 '94898','36430','57025','20601','82080', 447 '33869','22728','35834','29086','92645', 448 '98584','98072','11652','78093','57553', 449 '43830','71144','53565','18700','90209', 450 '71256','38353','54364','28571','96560', 451 '57839','56355','50679','45266','84680', 452 '34306','34972','48530','30106','15371', 453 '92380','84247','92292','68852','13338', 454 '34594','82602','70073','98069','85066', 455 '47289','11686','98862','26217','47529', 456 '63294','51793','35926','24227','14196', 457 '24594','32489','99060','49472','43432', 458 '49211','14312','88137','47369','56877', 459 '20534','81755','15794','12318','21060', 460 '73134','41255','63073','81003','73873', 461 '66057','51184','51195','45676','92696', 462 '70450','90669','98338','25264','38919', 463 '59226','58581','60298','17895','19489', 464 '52301','80846','95464','68770','51634', 465 '19988','18367','18421','11618','67975', 466 '25494','41352','95430','15734','62585', 467 '97173','33773','10425','75675','53535', 468 '17879','41967','12197','67998','79658', 469 '59130','72592','14851','43933','68101', 470 '50636','25717','71286','24660','58058', 471 '72991','95042','15543','33122','69280', 472 '11912','59386','27642','65177','17672', 473 '33467','64592','36335','54010','18767', 474 '63193','42361','49254','33113','33159', 475 '36479','59080','11855','81963','31016', 476 '49140','29392','41836','32958','53163', 477 '13844','73146','23952','65148','93498', 478 '14530','46131','58454','13376','13378', 479 '83986','12320','17193','59852','46081', 480 '98533','52389','13086','68843','31013', 481 '13261','60560','13443','45533','83583', 482 '11489','58218','19753','22911','25115', 483 '86709','27156','32669','13123','51933', 484 '39214','41331','66943','14155','69998', 485 '49101','70070','35076','14242','73021', 486 '59494','15782','29752','37914','74686', 487 '83086','34473','15751','81084','49230', 488 '91894','60624','17819','28810','63180', 489 '56224','39459','55233','75752','43639', 490 '55349','86057','62361','50788','31830', 491 '58062','18218','85761','60083','45484', 492 '21204','90229','70041','41162','35390', 493 '16364','39500','68908','26689','52868', 494 '81335','40146','11340','61527','61794', 495 '71997','30415','59004','29450','58117', 496 '69952','33562','83833','27385','61860', 497 '96435','48333','23065','32961','84919', 498 '61997','99132','22815','56600','68730', 499 '48017','95694','32919','88217','27116', 500 '28239','58032','18884','16791','21343', 501 '97462','18569','75660','15475') 502 intersect 503 select ca_zip 504 from (SELECT substr(ca_zip,1,5) ca_zip,count(*) cnt 505 FROM customer_address, customer 506 WHERE ca_address_sk = c_current_addr_sk and 507 c_preferred_cust_flag='Y' 508 group by ca_zip 509 having count(*) > 10)A1)A2) V1 510 where ss_store_sk = s_store_sk 511 and ss_sold_date_sk = d_date_sk 512 and d_qoy = 2 and d_year = 1998 513 and (substr(s_zip,1,2) = substr(V1.ca_zip,1,2)) 514 group by s_store_name 515 order by s_store_name 516 limit 100;`, 517 }, 518 { 519 Query: ` 520 -- start query 9 in stream 0 using template query9.tpl 521 select case when (select count(*) 522 from store_sales 523 where ss_quantity between 1 and 20) > 1071 524 then (select avg(ss_ext_tax) 525 from store_sales 526 where ss_quantity between 1 and 20) 527 else (select avg(ss_net_paid_inc_tax) 528 from store_sales 529 where ss_quantity between 1 and 20) end bucket1 , 530 case when (select count(*) 531 from store_sales 532 where ss_quantity between 21 and 40) > 39161 533 then (select avg(ss_ext_tax) 534 from store_sales 535 where ss_quantity between 21 and 40) 536 else (select avg(ss_net_paid_inc_tax) 537 from store_sales 538 where ss_quantity between 21 and 40) end bucket2, 539 case when (select count(*) 540 from store_sales 541 where ss_quantity between 41 and 60) > 29434 542 then (select avg(ss_ext_tax) 543 from store_sales 544 where ss_quantity between 41 and 60) 545 else (select avg(ss_net_paid_inc_tax) 546 from store_sales 547 where ss_quantity between 41 and 60) end bucket3, 548 case when (select count(*) 549 from store_sales 550 where ss_quantity between 61 and 80) > 6568 551 then (select avg(ss_ext_tax) 552 from store_sales 553 where ss_quantity between 61 and 80) 554 else (select avg(ss_net_paid_inc_tax) 555 from store_sales 556 where ss_quantity between 61 and 80) end bucket4, 557 case when (select count(*) 558 from store_sales 559 where ss_quantity between 81 and 100) > 21216 560 then (select avg(ss_ext_tax) 561 from store_sales 562 where ss_quantity between 81 and 100) 563 else (select avg(ss_net_paid_inc_tax) 564 from store_sales 565 where ss_quantity between 81 and 100) end bucket5 566 from reason 567 where r_reason_sk = 1 568 ;`, 569 }, 570 { 571 Query: ` 572 -- start query 10 in stream 0 using template query10.tpl 573 select 574 cd_gender, 575 cd_marital_status, 576 cd_education_status, 577 count(*) cnt1, 578 cd_purchase_estimate, 579 count(*) cnt2, 580 cd_credit_rating, 581 count(*) cnt3, 582 cd_dep_count, 583 count(*) cnt4, 584 cd_dep_employed_count, 585 count(*) cnt5, 586 cd_dep_college_count, 587 count(*) cnt6 588 from 589 customer c,customer_address ca,customer_demographics 590 where 591 c.c_current_addr_sk = ca.ca_address_sk and 592 ca_county in ('Fairfield County','Campbell County','Washtenaw County','Escambia County','Cleburne County') and 593 cd_demo_sk = c.c_current_cdemo_sk and 594 exists (select * 595 from store_sales,date_dim 596 where c.c_customer_sk = ss_customer_sk and 597 ss_sold_date_sk = d_date_sk and 598 d_year = 2001 and 599 d_moy between 3 and 3+3) and 600 (exists (select * 601 from web_sales,date_dim 602 where c.c_customer_sk = ws_bill_customer_sk and 603 ws_sold_date_sk = d_date_sk and 604 d_year = 2001 and 605 d_moy between 3 ANd 3+3) or 606 exists (select * 607 from catalog_sales,date_dim 608 where c.c_customer_sk = cs_ship_customer_sk and 609 cs_sold_date_sk = d_date_sk and 610 d_year = 2001 and 611 d_moy between 3 and 3+3)) 612 group by cd_gender, 613 cd_marital_status, 614 cd_education_status, 615 cd_purchase_estimate, 616 cd_credit_rating, 617 cd_dep_count, 618 cd_dep_employed_count, 619 cd_dep_college_count 620 order by cd_gender, 621 cd_marital_status, 622 cd_education_status, 623 cd_purchase_estimate, 624 cd_credit_rating, 625 cd_dep_count, 626 cd_dep_employed_count, 627 cd_dep_college_count 628 limit 100;`, 629 }, 630 { 631 Query: ` 632 -- start query 11 in stream 0 using template query11.tpl 633 with year_total as ( 634 select c_customer_id customer_id 635 ,c_first_name customer_first_name 636 ,c_last_name customer_last_name 637 ,c_preferred_cust_flag customer_preferred_cust_flag 638 ,c_birth_country customer_birth_country 639 ,c_login customer_login 640 ,c_email_address customer_email_address 641 ,d_year dyear 642 ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total 643 ,'s' sale_type 644 from customer 645 ,store_sales 646 ,date_dim 647 where c_customer_sk = ss_customer_sk 648 and ss_sold_date_sk = d_date_sk 649 group by c_customer_id 650 ,c_first_name 651 ,c_last_name 652 ,c_preferred_cust_flag 653 ,c_birth_country 654 ,c_login 655 ,c_email_address 656 ,d_year 657 union all 658 select c_customer_id customer_id 659 ,c_first_name customer_first_name 660 ,c_last_name customer_last_name 661 ,c_preferred_cust_flag customer_preferred_cust_flag 662 ,c_birth_country customer_birth_country 663 ,c_login customer_login 664 ,c_email_address customer_email_address 665 ,d_year dyear 666 ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total 667 ,'w' sale_type 668 from customer 669 ,web_sales 670 ,date_dim 671 where c_customer_sk = ws_bill_customer_sk 672 and ws_sold_date_sk = d_date_sk 673 group by c_customer_id 674 ,c_first_name 675 ,c_last_name 676 ,c_preferred_cust_flag 677 ,c_birth_country 678 ,c_login 679 ,c_email_address 680 ,d_year 681 ) 682 select 683 t_s_secyear.customer_id 684 ,t_s_secyear.customer_first_name 685 ,t_s_secyear.customer_last_name 686 ,t_s_secyear.customer_email_address 687 from year_total t_s_firstyear 688 ,year_total t_s_secyear 689 ,year_total t_w_firstyear 690 ,year_total t_w_secyear 691 where t_s_secyear.customer_id = t_s_firstyear.customer_id 692 and t_s_firstyear.customer_id = t_w_secyear.customer_id 693 and t_s_firstyear.customer_id = t_w_firstyear.customer_id 694 and t_s_firstyear.sale_type = 's' 695 and t_w_firstyear.sale_type = 'w' 696 and t_s_secyear.sale_type = 's' 697 and t_w_secyear.sale_type = 'w' 698 and t_s_firstyear.dyear = 1998 699 and t_s_secyear.dyear = 1998+1 700 and t_w_firstyear.dyear = 1998 701 and t_w_secyear.dyear = 1998+1 702 and t_s_firstyear.year_total > 0 703 and t_w_firstyear.year_total > 0 704 and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end 705 > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end 706 order by t_s_secyear.customer_id 707 ,t_s_secyear.customer_first_name 708 ,t_s_secyear.customer_last_name 709 ,t_s_secyear.customer_email_address 710 limit 100;`, 711 }, 712 { 713 Skip: true, 714 Query: ` 715 -- start query 12 in stream 0 using template query12.tpl 716 select i_item_id 717 ,i_item_desc 718 ,i_category 719 ,i_class 720 ,i_current_price 721 ,sum(ws_ext_sales_price) as itemrevenue 722 ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over 723 (partition by i_class) as revenueratio 724 from 725 web_sales 726 ,item 727 ,date_dim 728 where 729 ws_item_sk = i_item_sk 730 and i_category in ('Men', 'Books', 'Electronics') 731 and ws_sold_date_sk = d_date_sk 732 and d_date between cast('2001-06-15' as date) 733 and (cast('2001-06-15' as date) + interval 30 day) 734 group by 735 i_item_id 736 ,i_item_desc 737 ,i_category 738 ,i_class 739 ,i_current_price 740 order by 741 i_category 742 ,i_class 743 ,i_item_id 744 ,i_item_desc 745 ,revenueratio 746 limit 100;`, 747 }, 748 { 749 Query: ` 750 -- start query 13 in stream 0 using template query13.tpl 751 select avg(ss_quantity) 752 ,avg(ss_ext_sales_price) 753 ,avg(ss_ext_wholesale_cost) 754 ,sum(ss_ext_wholesale_cost) 755 from store_sales 756 ,store 757 ,customer_demographics 758 ,household_demographics 759 ,customer_address 760 ,date_dim 761 where s_store_sk = ss_store_sk 762 and ss_sold_date_sk = d_date_sk and d_year = 2001 763 and((ss_hdemo_sk=hd_demo_sk 764 and cd_demo_sk = ss_cdemo_sk 765 and cd_marital_status = 'M' 766 and cd_education_status = 'College' 767 and ss_sales_price between 100.00 and 150.00 768 and hd_dep_count = 3 769 )or 770 (ss_hdemo_sk=hd_demo_sk 771 and cd_demo_sk = ss_cdemo_sk 772 and cd_marital_status = 'D' 773 and cd_education_status = 'Primary' 774 and ss_sales_price between 50.00 and 100.00 775 and hd_dep_count = 1 776 ) or 777 (ss_hdemo_sk=hd_demo_sk 778 and cd_demo_sk = ss_cdemo_sk 779 and cd_marital_status = 'W' 780 and cd_education_status = '2 yr Degree' 781 and ss_sales_price between 150.00 and 200.00 782 and hd_dep_count = 1 783 )) 784 and((ss_addr_sk = ca_address_sk 785 and ca_country = 'United States' 786 and ca_state in ('IL', 'TN', 'TX') 787 and ss_net_profit between 100 and 200 788 ) or 789 (ss_addr_sk = ca_address_sk 790 and ca_country = 'United States' 791 and ca_state in ('WY', 'OH', 'ID') 792 and ss_net_profit between 150 and 300 793 ) or 794 (ss_addr_sk = ca_address_sk 795 and ca_country = 'United States' 796 and ca_state in ('MS', 'SC', 'IA') 797 and ss_net_profit between 50 and 250 798 )) 799 ;`, 800 }, 801 { 802 Query: ` 803 -- start query 14 in stream 0 using template query14.tpl 804 with cross_items as 805 (select i_item_sk ss_item_sk 806 from item, 807 (select iss.i_brand_id brand_id 808 ,iss.i_class_id class_id 809 ,iss.i_category_id category_id 810 from store_sales 811 ,item iss 812 ,date_dim d1 813 where ss_item_sk = iss.i_item_sk 814 and ss_sold_date_sk = d1.d_date_sk 815 and d1.d_year between 1999 AND 1999 + 2 816 intersect 817 select ics.i_brand_id 818 ,ics.i_class_id 819 ,ics.i_category_id 820 from catalog_sales 821 ,item ics 822 ,date_dim d2 823 where cs_item_sk = ics.i_item_sk 824 and cs_sold_date_sk = d2.d_date_sk 825 and d2.d_year between 1999 AND 1999 + 2 826 intersect 827 select iws.i_brand_id 828 ,iws.i_class_id 829 ,iws.i_category_id 830 from web_sales 831 ,item iws 832 ,date_dim d3 833 where ws_item_sk = iws.i_item_sk 834 and ws_sold_date_sk = d3.d_date_sk 835 and d3.d_year between 1999 AND 1999 + 2) 836 where i_brand_id = brand_id 837 and i_class_id = class_id 838 and i_category_id = category_id 839 ), 840 avg_sales as 841 (select avg(quantity*list_price) average_sales 842 from (select ss_quantity quantity 843 ,ss_list_price list_price 844 from store_sales 845 ,date_dim 846 where ss_sold_date_sk = d_date_sk 847 and d_year between 1999 and 1999 + 2 848 union all 849 select cs_quantity quantity 850 ,cs_list_price list_price 851 from catalog_sales 852 ,date_dim 853 where cs_sold_date_sk = d_date_sk 854 and d_year between 1999 and 1999 + 2 855 union all 856 select ws_quantity quantity 857 ,ws_list_price list_price 858 from web_sales 859 ,date_dim 860 where ws_sold_date_sk = d_date_sk 861 and d_year between 1999 and 1999 + 2) x) 862 select channel, i_brand_id,i_class_id,i_category_id,sum(sales), sum(number_sales) 863 from( 864 select 'store' channel, i_brand_id,i_class_id 865 ,i_category_id,sum(ss_quantity*ss_list_price) sales 866 , count(*) number_sales 867 from store_sales 868 ,item 869 ,date_dim 870 where ss_item_sk in (select ss_item_sk from cross_items) 871 and ss_item_sk = i_item_sk 872 and ss_sold_date_sk = d_date_sk 873 and d_year = 1999+2 874 and d_moy = 11 875 group by i_brand_id,i_class_id,i_category_id 876 having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) 877 union all 878 select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales 879 from catalog_sales 880 ,item 881 ,date_dim 882 where cs_item_sk in (select ss_item_sk from cross_items) 883 and cs_item_sk = i_item_sk 884 and cs_sold_date_sk = d_date_sk 885 and d_year = 1999+2 886 and d_moy = 11 887 group by i_brand_id,i_class_id,i_category_id 888 having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) 889 union all 890 select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales 891 from web_sales 892 ,item 893 ,date_dim 894 where ws_item_sk in (select ss_item_sk from cross_items) 895 and ws_item_sk = i_item_sk 896 and ws_sold_date_sk = d_date_sk 897 and d_year = 1999+2 898 and d_moy = 11 899 group by i_brand_id,i_class_id,i_category_id 900 having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) 901 ) y 902 group by rollup (channel, i_brand_id,i_class_id,i_category_id) 903 order by channel,i_brand_id,i_class_id,i_category_id 904 limit 100; 905 with cross_items as 906 (select i_item_sk ss_item_sk 907 from item, 908 (select iss.i_brand_id brand_id 909 ,iss.i_class_id class_id 910 ,iss.i_category_id category_id 911 from store_sales 912 ,item iss 913 ,date_dim d1 914 where ss_item_sk = iss.i_item_sk 915 and ss_sold_date_sk = d1.d_date_sk 916 and d1.d_year between 1999 AND 1999 + 2 917 intersect 918 select ics.i_brand_id 919 ,ics.i_class_id 920 ,ics.i_category_id 921 from catalog_sales 922 ,item ics 923 ,date_dim d2 924 where cs_item_sk = ics.i_item_sk 925 and cs_sold_date_sk = d2.d_date_sk 926 and d2.d_year between 1999 AND 1999 + 2 927 intersect 928 select iws.i_brand_id 929 ,iws.i_class_id 930 ,iws.i_category_id 931 from web_sales 932 ,item iws 933 ,date_dim d3 934 where ws_item_sk = iws.i_item_sk 935 and ws_sold_date_sk = d3.d_date_sk 936 and d3.d_year between 1999 AND 1999 + 2) x 937 where i_brand_id = brand_id 938 and i_class_id = class_id 939 and i_category_id = category_id 940 ), 941 avg_sales as 942 (select avg(quantity*list_price) average_sales 943 from (select ss_quantity quantity 944 ,ss_list_price list_price 945 from store_sales 946 ,date_dim 947 where ss_sold_date_sk = d_date_sk 948 and d_year between 1999 and 1999 + 2 949 union all 950 select cs_quantity quantity 951 ,cs_list_price list_price 952 from catalog_sales 953 ,date_dim 954 where cs_sold_date_sk = d_date_sk 955 and d_year between 1999 and 1999 + 2 956 union all 957 select ws_quantity quantity 958 ,ws_list_price list_price 959 from web_sales 960 ,date_dim 961 where ws_sold_date_sk = d_date_sk 962 and d_year between 1999 and 1999 + 2) x) 963 select this_year.channel ty_channel 964 ,this_year.i_brand_id ty_brand 965 ,this_year.i_class_id ty_class 966 ,this_year.i_category_id ty_category 967 ,this_year.sales ty_sales 968 ,this_year.number_sales ty_number_sales 969 ,last_year.channel ly_channel 970 ,last_year.i_brand_id ly_brand 971 ,last_year.i_class_id ly_class 972 ,last_year.i_category_id ly_category 973 ,last_year.sales ly_sales 974 ,last_year.number_sales ly_number_sales 975 from 976 (select 'store' channel, i_brand_id,i_class_id,i_category_id 977 ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales 978 from store_sales 979 ,item 980 ,date_dim 981 where ss_item_sk in (select ss_item_sk from cross_items) 982 and ss_item_sk = i_item_sk 983 and ss_sold_date_sk = d_date_sk 984 and d_week_seq = (select d_week_seq 985 from date_dim 986 where d_year = 1999 + 1 987 and d_moy = 12 988 and d_dom = 3) 989 group by i_brand_id,i_class_id,i_category_id 990 having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, 991 (select 'store' channel, i_brand_id,i_class_id 992 ,i_category_id, sum(ss_quantity*ss_list_price) sales, count(*) number_sales 993 from store_sales 994 ,item 995 ,date_dim 996 where ss_item_sk in (select ss_item_sk from cross_items) 997 and ss_item_sk = i_item_sk 998 and ss_sold_date_sk = d_date_sk 999 and d_week_seq = (select d_week_seq 1000 from date_dim 1001 where d_year = 1999 1002 and d_moy = 12 1003 and d_dom = 3) 1004 group by i_brand_id,i_class_id,i_category_id 1005 having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year 1006 where this_year.i_brand_id= last_year.i_brand_id 1007 and this_year.i_class_id = last_year.i_class_id 1008 and this_year.i_category_id = last_year.i_category_id 1009 order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id 1010 limit 100;`, 1011 Skip: true, 1012 }, 1013 { 1014 Query: ` 1015 -- start query 15 in stream 0 using template query15.tpl 1016 select ca_zip 1017 ,sum(cs_sales_price) 1018 from catalog_sales 1019 ,customer 1020 ,customer_address 1021 ,date_dim 1022 where cs_bill_customer_sk = c_customer_sk 1023 and c_current_addr_sk = ca_address_sk 1024 and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', 1025 '85392', '85460', '80348', '81792') 1026 or ca_state in ('CA','WA','GA') 1027 or cs_sales_price > 500) 1028 and cs_sold_date_sk = d_date_sk 1029 and d_qoy = 2 and d_year = 2001 1030 group by ca_zip 1031 order by ca_zip 1032 limit 100;`, 1033 }, 1034 { 1035 Query: ` 1036 -- start query 16 in stream 0 using template query16.tpl 1037 select 1038 count(distinct cs_order_number) as "order count" 1039 ,sum(cs_ext_ship_cost) as "total shipping cost" 1040 ,sum(cs_net_profit) as "total net profit" 1041 from 1042 catalog_sales cs1 1043 ,date_dim 1044 ,customer_address 1045 ,call_center 1046 where 1047 d_date between '2002-4-01' and 1048 (cast('2002-4-01' as date) + interval 60 day) 1049 and cs1.cs_ship_date_sk = d_date_sk 1050 and cs1.cs_ship_addr_sk = ca_address_sk 1051 and ca_state = 'PA' 1052 and cs1.cs_call_center_sk = cc_call_center_sk 1053 and cc_county in ('Williamson County','Williamson County','Williamson County','Williamson County', 1054 'Williamson County' 1055 ) 1056 and exists (select * 1057 from catalog_sales cs2 1058 where cs1.cs_order_number = cs2.cs_order_number 1059 and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) 1060 and not exists(select * 1061 from catalog_returns cr1 1062 where cs1.cs_order_number = cr1.cr_order_number) 1063 order by count(distinct cs_order_number) 1064 limit 100;`, 1065 }, 1066 { 1067 Query: ` 1068 -- start query 17 in stream 0 using template query17.tpl 1069 select i_item_id 1070 ,i_item_desc 1071 ,s_state 1072 ,count(ss_quantity) as store_sales_quantitycount 1073 ,avg(ss_quantity) as store_sales_quantityave 1074 ,stddev_samp(ss_quantity) as store_sales_quantitystdev 1075 ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov 1076 ,count(sr_return_quantity) as store_returns_quantitycount 1077 ,avg(sr_return_quantity) as store_returns_quantityave 1078 ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev 1079 ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov 1080 ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave 1081 ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev 1082 ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov 1083 from store_sales 1084 ,store_returns 1085 ,catalog_sales 1086 ,date_dim d1 1087 ,date_dim d2 1088 ,date_dim d3 1089 ,store 1090 ,item 1091 where d1.d_quarter_name = '2001Q1' 1092 and d1.d_date_sk = ss_sold_date_sk 1093 and i_item_sk = ss_item_sk 1094 and s_store_sk = ss_store_sk 1095 and ss_customer_sk = sr_customer_sk 1096 and ss_item_sk = sr_item_sk 1097 and ss_ticket_number = sr_ticket_number 1098 and sr_returned_date_sk = d2.d_date_sk 1099 and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') 1100 and sr_customer_sk = cs_bill_customer_sk 1101 and sr_item_sk = cs_item_sk 1102 and cs_sold_date_sk = d3.d_date_sk 1103 and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') 1104 group by i_item_id 1105 ,i_item_desc 1106 ,s_state 1107 order by i_item_id 1108 ,i_item_desc 1109 ,s_state 1110 limit 100;`, 1111 }, 1112 { 1113 Query: ` 1114 -- start query 18 in stream 0 using template query18.tpl 1115 select i_item_id, 1116 ca_country, 1117 ca_state, 1118 ca_county, 1119 avg( cast(cs_quantity as decimal(12,2))) agg1, 1120 avg( cast(cs_list_price as decimal(12,2))) agg2, 1121 avg( cast(cs_coupon_amt as decimal(12,2))) agg3, 1122 avg( cast(cs_sales_price as decimal(12,2))) agg4, 1123 avg( cast(cs_net_profit as decimal(12,2))) agg5, 1124 avg( cast(c_birth_year as decimal(12,2))) agg6, 1125 avg( cast(cd1.cd_dep_count as decimal(12,2))) agg7 1126 from catalog_sales, customer_demographics cd1, 1127 customer_demographics cd2, customer, customer_address, date_dim, item 1128 where cs_sold_date_sk = d_date_sk and 1129 cs_item_sk = i_item_sk and 1130 cs_bill_cdemo_sk = cd1.cd_demo_sk and 1131 cs_bill_customer_sk = c_customer_sk and 1132 cd1.cd_gender = 'F' and 1133 cd1.cd_education_status = 'Primary' and 1134 c_current_cdemo_sk = cd2.cd_demo_sk and 1135 c_current_addr_sk = ca_address_sk and 1136 c_birth_month in (1,3,7,11,10,4) and 1137 d_year = 2001 and 1138 ca_state in ('AL','MO','TN' 1139 ,'GA','MT','IN','CA') 1140 group by rollup (i_item_id, ca_country, ca_state, ca_county) 1141 order by ca_country, 1142 ca_state, 1143 ca_county, 1144 i_item_id 1145 limit 100;`, 1146 Skip: true, 1147 }, 1148 { 1149 Query: ` 1150 -- start query 19 in stream 0 using template query19.tpl 1151 select i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, 1152 sum(ss_ext_sales_price) ext_price 1153 from date_dim, store_sales, item,customer,customer_address,store 1154 where d_date_sk = ss_sold_date_sk 1155 and ss_item_sk = i_item_sk 1156 and i_manager_id=14 1157 and d_moy=11 1158 and d_year=2002 1159 and ss_customer_sk = c_customer_sk 1160 and c_current_addr_sk = ca_address_sk 1161 and substr(ca_zip,1,5) <> substr(s_zip,1,5) 1162 and ss_store_sk = s_store_sk 1163 group by i_brand 1164 ,i_brand_id 1165 ,i_manufact_id 1166 ,i_manufact 1167 order by ext_price desc 1168 ,i_brand 1169 ,i_brand_id 1170 ,i_manufact_id 1171 ,i_manufact 1172 limit 100 ;`, 1173 }, 1174 { 1175 Query: ` 1176 -- start query 20 in stream 0 using template query20.tpl 1177 select i_item_id 1178 ,i_item_desc 1179 ,i_category 1180 ,i_class 1181 ,i_current_price 1182 ,sum(cs_ext_sales_price) as itemrevenue 1183 ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over 1184 (partition by i_class) as revenueratio 1185 from catalog_sales 1186 ,item 1187 ,date_dim 1188 where cs_item_sk = i_item_sk 1189 and i_category in ('Books', 'Music', 'Sports') 1190 and cs_sold_date_sk = d_date_sk 1191 and d_date between cast('2002-06-18' as date) 1192 and (cast('2002-06-18' as date) + interval 30 day) 1193 group by i_item_id 1194 ,i_item_desc 1195 ,i_category 1196 ,i_class 1197 ,i_current_price 1198 order by i_category 1199 ,i_class 1200 ,i_item_id 1201 ,i_item_desc 1202 ,revenueratio 1203 limit 100;`, 1204 }, 1205 { 1206 Query: ` 1207 -- start query 21 in stream 0 using template query21.tpl 1208 select * 1209 from(select w_warehouse_name 1210 ,i_item_id 1211 ,sum(case when (cast(d_date as date) < cast ('1999-06-22' as date)) 1212 then inv_quantity_on_hand 1213 else 0 end) as inv_before 1214 ,sum(case when (cast(d_date as date) >= cast ('1999-06-22' as date)) 1215 then inv_quantity_on_hand 1216 else 0 end) as inv_after 1217 from inventory 1218 ,warehouse 1219 ,item 1220 ,date_dim 1221 where i_current_price between 0.99 and 1.49 1222 and i_item_sk = inv_item_sk 1223 and inv_warehouse_sk = w_warehouse_sk 1224 and inv_date_sk = d_date_sk 1225 and d_date between (cast ('1999-06-22' as date) - interval 30 day) 1226 and (cast ('1999-06-22' as date) + interval 30 day) 1227 group by w_warehouse_name, i_item_id) x 1228 where (case when inv_before > 0 1229 then inv_after / inv_before 1230 else null 1231 end) between 2.0/3.0 and 3.0/2.0 1232 order by w_warehouse_name 1233 ,i_item_id 1234 limit 100;`, 1235 }, 1236 { 1237 Query: ` 1238 -- start query 22 in stream 0 using template query22.tpl 1239 select i_product_name 1240 ,i_brand 1241 ,i_class 1242 ,i_category 1243 ,avg(inv_quantity_on_hand) qoh 1244 from inventory 1245 ,date_dim 1246 ,item 1247 where inv_date_sk=d_date_sk 1248 and inv_item_sk=i_item_sk 1249 and d_month_seq between 1200 and 1200 + 11 1250 group by rollup(i_product_name 1251 ,i_brand 1252 ,i_class 1253 ,i_category) 1254 order by qoh, i_product_name, i_brand, i_class, i_category 1255 limit 100;`, 1256 Skip: true, 1257 }, 1258 { 1259 Query: ` 1260 -- start query 23 in stream 0 using template query23.tpl 1261 with frequent_ss_items as 1262 (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt 1263 from store_sales 1264 ,date_dim 1265 ,item 1266 where ss_sold_date_sk = d_date_sk 1267 and ss_item_sk = i_item_sk 1268 and d_year in (2000,2000+1,2000+2,2000+3) 1269 group by substr(i_item_desc,1,30),i_item_sk,d_date 1270 having count(*) >4), 1271 max_store_sales as 1272 (select max(csales) tpcds_cmax 1273 from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales 1274 from store_sales 1275 ,customer 1276 ,date_dim 1277 where ss_customer_sk = c_customer_sk 1278 and ss_sold_date_sk = d_date_sk 1279 and d_year in (2000,2000+1,2000+2,2000+3) 1280 group by c_customer_sk)), 1281 best_ss_customer as 1282 (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales 1283 from store_sales 1284 ,customer 1285 where ss_customer_sk = c_customer_sk 1286 group by c_customer_sk 1287 having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select 1288 * 1289 from 1290 max_store_sales)) 1291 select sum(sales) 1292 from (select cs_quantity*cs_list_price sales 1293 from catalog_sales 1294 ,date_dim 1295 where d_year = 2000 1296 and d_moy = 7 1297 and cs_sold_date_sk = d_date_sk 1298 and cs_item_sk in (select item_sk from frequent_ss_items) 1299 and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) 1300 union all 1301 select ws_quantity*ws_list_price sales 1302 from web_sales 1303 ,date_dim 1304 where d_year = 2000 1305 and d_moy = 7 1306 and ws_sold_date_sk = d_date_sk 1307 and ws_item_sk in (select item_sk from frequent_ss_items) 1308 and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) 1309 limit 100; 1310 with frequent_ss_items as 1311 (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt 1312 from store_sales 1313 ,date_dim 1314 ,item 1315 where ss_sold_date_sk = d_date_sk 1316 and ss_item_sk = i_item_sk 1317 and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) 1318 group by substr(i_item_desc,1,30),i_item_sk,d_date 1319 having count(*) >4), 1320 max_store_sales as 1321 (select max(csales) tpcds_cmax 1322 from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales 1323 from store_sales 1324 ,customer 1325 ,date_dim 1326 where ss_customer_sk = c_customer_sk 1327 and ss_sold_date_sk = d_date_sk 1328 and d_year in (2000,2000+1,2000+2,2000+3) 1329 group by c_customer_sk)), 1330 best_ss_customer as 1331 (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales 1332 from store_sales 1333 ,customer 1334 where ss_customer_sk = c_customer_sk 1335 group by c_customer_sk 1336 having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select 1337 * 1338 from max_store_sales)) 1339 select c_last_name,c_first_name,sales 1340 from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales 1341 from catalog_sales 1342 ,customer 1343 ,date_dim 1344 where d_year = 2000 1345 and d_moy = 7 1346 and cs_sold_date_sk = d_date_sk 1347 and cs_item_sk in (select item_sk from frequent_ss_items) 1348 and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) 1349 and cs_bill_customer_sk = c_customer_sk 1350 group by c_last_name,c_first_name 1351 union all 1352 select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales 1353 from web_sales 1354 ,customer 1355 ,date_dim 1356 where d_year = 2000 1357 and d_moy = 7 1358 and ws_sold_date_sk = d_date_sk 1359 and ws_item_sk in (select item_sk from frequent_ss_items) 1360 and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) 1361 and ws_bill_customer_sk = c_customer_sk 1362 group by c_last_name,c_first_name) 1363 order by c_last_name,c_first_name,sales 1364 limit 100;`, 1365 }, 1366 { 1367 Query: ` 1368 -- start query 24 in stream 0 using template query24.tpl 1369 with ssales as 1370 (select c_last_name 1371 ,c_first_name 1372 ,s_store_name 1373 ,ca_state 1374 ,s_state 1375 ,i_color 1376 ,i_current_price 1377 ,i_manager_id 1378 ,i_units 1379 ,i_size 1380 ,sum(ss_net_paid) netpaid 1381 from store_sales 1382 ,store_returns 1383 ,store 1384 ,item 1385 ,customer 1386 ,customer_address 1387 where ss_ticket_number = sr_ticket_number 1388 and ss_item_sk = sr_item_sk 1389 and ss_customer_sk = c_customer_sk 1390 and ss_item_sk = i_item_sk 1391 and ss_store_sk = s_store_sk 1392 and c_current_addr_sk = ca_address_sk 1393 and c_birth_country <> upper(ca_country) 1394 and s_zip = ca_zip 1395 and s_market_id=5 1396 group by c_last_name 1397 ,c_first_name 1398 ,s_store_name 1399 ,ca_state 1400 ,s_state 1401 ,i_color 1402 ,i_current_price 1403 ,i_manager_id 1404 ,i_units 1405 ,i_size) 1406 select c_last_name 1407 ,c_first_name 1408 ,s_store_name 1409 ,sum(netpaid) paid 1410 from ssales 1411 where i_color = 'aquamarine' 1412 group by c_last_name 1413 ,c_first_name 1414 ,s_store_name 1415 having sum(netpaid) > (select 0.05*avg(netpaid) 1416 from ssales) 1417 order by c_last_name 1418 ,c_first_name 1419 ,s_store_name 1420 ; 1421 with ssales as 1422 (select c_last_name 1423 ,c_first_name 1424 ,s_store_name 1425 ,ca_state 1426 ,s_state 1427 ,i_color 1428 ,i_current_price 1429 ,i_manager_id 1430 ,i_units 1431 ,i_size 1432 ,sum(ss_net_paid) netpaid 1433 from store_sales 1434 ,store_returns 1435 ,store 1436 ,item 1437 ,customer 1438 ,customer_address 1439 where ss_ticket_number = sr_ticket_number 1440 and ss_item_sk = sr_item_sk 1441 and ss_customer_sk = c_customer_sk 1442 and ss_item_sk = i_item_sk 1443 and ss_store_sk = s_store_sk 1444 and c_current_addr_sk = ca_address_sk 1445 and c_birth_country <> upper(ca_country) 1446 and s_zip = ca_zip 1447 and s_market_id = 5 1448 group by c_last_name 1449 ,c_first_name 1450 ,s_store_name 1451 ,ca_state 1452 ,s_state 1453 ,i_color 1454 ,i_current_price 1455 ,i_manager_id 1456 ,i_units 1457 ,i_size) 1458 select c_last_name 1459 ,c_first_name 1460 ,s_store_name 1461 ,sum(netpaid) paid 1462 from ssales 1463 where i_color = 'seashell' 1464 group by c_last_name 1465 ,c_first_name 1466 ,s_store_name 1467 having sum(netpaid) > (select 0.05*avg(netpaid) 1468 from ssales) 1469 order by c_last_name 1470 ,c_first_name 1471 ,s_store_name 1472 ;`, 1473 }, 1474 { 1475 Query: ` 1476 -- start query 25 in stream 0 using template query25.tpl 1477 select 1478 i_item_id 1479 ,i_item_desc 1480 ,s_store_id 1481 ,s_store_name 1482 ,max(ss_net_profit) as store_sales_profit 1483 ,max(sr_net_loss) as store_returns_loss 1484 ,max(cs_net_profit) as catalog_sales_profit 1485 from 1486 store_sales 1487 ,store_returns 1488 ,catalog_sales 1489 ,date_dim d1 1490 ,date_dim d2 1491 ,date_dim d3 1492 ,store 1493 ,item 1494 where 1495 d1.d_moy = 4 1496 and d1.d_year = 1999 1497 and d1.d_date_sk = ss_sold_date_sk 1498 and i_item_sk = ss_item_sk 1499 and s_store_sk = ss_store_sk 1500 and ss_customer_sk = sr_customer_sk 1501 and ss_item_sk = sr_item_sk 1502 and ss_ticket_number = sr_ticket_number 1503 and sr_returned_date_sk = d2.d_date_sk 1504 and d2.d_moy between 4 and 10 1505 and d2.d_year = 1999 1506 and sr_customer_sk = cs_bill_customer_sk 1507 and sr_item_sk = cs_item_sk 1508 and cs_sold_date_sk = d3.d_date_sk 1509 and d3.d_moy between 4 and 10 1510 and d3.d_year = 1999 1511 group by 1512 i_item_id 1513 ,i_item_desc 1514 ,s_store_id 1515 ,s_store_name 1516 order by 1517 i_item_id 1518 ,i_item_desc 1519 ,s_store_id 1520 ,s_store_name 1521 limit 100;`, 1522 }, 1523 { 1524 Query: ` 1525 -- start query 26 in stream 0 using template query26.tpl 1526 select i_item_id, 1527 avg(cs_quantity) agg1, 1528 avg(cs_list_price) agg2, 1529 avg(cs_coupon_amt) agg3, 1530 avg(cs_sales_price) agg4 1531 from catalog_sales, customer_demographics, date_dim, item, promotion 1532 where cs_sold_date_sk = d_date_sk and 1533 cs_item_sk = i_item_sk and 1534 cs_bill_cdemo_sk = cd_demo_sk and 1535 cs_promo_sk = p_promo_sk and 1536 cd_gender = 'M' and 1537 cd_marital_status = 'W' and 1538 cd_education_status = 'Unknown' and 1539 (p_channel_email = 'N' or p_channel_event = 'N') and 1540 d_year = 2002 1541 group by i_item_id 1542 order by i_item_id 1543 limit 100;`, 1544 }, 1545 { 1546 Query: ` 1547 -- start query 27 in stream 0 using template query27.tpl 1548 select i_item_id, 1549 s_state, grouping(s_state) g_state, 1550 avg(ss_quantity) agg1, 1551 avg(ss_list_price) agg2, 1552 avg(ss_coupon_amt) agg3, 1553 avg(ss_sales_price) agg4 1554 from store_sales, customer_demographics, date_dim, store, item 1555 where ss_sold_date_sk = d_date_sk and 1556 ss_item_sk = i_item_sk and 1557 ss_store_sk = s_store_sk and 1558 ss_cdemo_sk = cd_demo_sk and 1559 cd_gender = 'M' and 1560 cd_marital_status = 'W' and 1561 cd_education_status = 'Secondary' and 1562 d_year = 1999 and 1563 s_state in ('TN','TN', 'TN', 'TN', 'TN', 'TN') 1564 group by rollup (i_item_id, s_state) 1565 order by i_item_id 1566 ,s_state 1567 limit 100;`, 1568 Skip: true, 1569 }, 1570 { 1571 Query: ` 1572 -- start query 28 in stream 0 using template query28.tpl 1573 select * 1574 from (select avg(ss_list_price) B1_LP 1575 ,count(ss_list_price) B1_CNT 1576 ,count(distinct ss_list_price) B1_CNTD 1577 from store_sales 1578 where ss_quantity between 0 and 5 1579 and (ss_list_price between 107 and 107+10 1580 or ss_coupon_amt between 1319 and 1319+1000 1581 or ss_wholesale_cost between 60 and 60+20)) B1, 1582 (select avg(ss_list_price) B2_LP 1583 ,count(ss_list_price) B2_CNT 1584 ,count(distinct ss_list_price) B2_CNTD 1585 from store_sales 1586 where ss_quantity between 6 and 10 1587 and (ss_list_price between 23 and 23+10 1588 or ss_coupon_amt between 825 and 825+1000 1589 or ss_wholesale_cost between 43 and 43+20)) B2, 1590 (select avg(ss_list_price) B3_LP 1591 ,count(ss_list_price) B3_CNT 1592 ,count(distinct ss_list_price) B3_CNTD 1593 from store_sales 1594 where ss_quantity between 11 and 15 1595 and (ss_list_price between 74 and 74+10 1596 or ss_coupon_amt between 4381 and 4381+1000 1597 or ss_wholesale_cost between 57 and 57+20)) B3, 1598 (select avg(ss_list_price) B4_LP 1599 ,count(ss_list_price) B4_CNT 1600 ,count(distinct ss_list_price) B4_CNTD 1601 from store_sales 1602 where ss_quantity between 16 and 20 1603 and (ss_list_price between 89 and 89+10 1604 or ss_coupon_amt between 3117 and 3117+1000 1605 or ss_wholesale_cost between 68 and 68+20)) B4, 1606 (select avg(ss_list_price) B5_LP 1607 ,count(ss_list_price) B5_CNT 1608 ,count(distinct ss_list_price) B5_CNTD 1609 from store_sales 1610 where ss_quantity between 21 and 25 1611 and (ss_list_price between 58 and 58+10 1612 or ss_coupon_amt between 9402 and 9402+1000 1613 or ss_wholesale_cost between 38 and 38+20)) B5, 1614 (select avg(ss_list_price) B6_LP 1615 ,count(ss_list_price) B6_CNT 1616 ,count(distinct ss_list_price) B6_CNTD 1617 from store_sales 1618 where ss_quantity between 26 and 30 1619 and (ss_list_price between 64 and 64+10 1620 or ss_coupon_amt between 5792 and 5792+1000 1621 or ss_wholesale_cost between 73 and 73+20)) B6 1622 limit 100;`, 1623 }, 1624 { 1625 Query: ` 1626 -- start query 29 in stream 0 using template query29.tpl 1627 select 1628 i_item_id 1629 ,i_item_desc 1630 ,s_store_id 1631 ,s_store_name 1632 ,max(ss_quantity) as store_sales_quantity 1633 ,max(sr_return_quantity) as store_returns_quantity 1634 ,max(cs_quantity) as catalog_sales_quantity 1635 from 1636 store_sales 1637 ,store_returns 1638 ,catalog_sales 1639 ,date_dim d1 1640 ,date_dim d2 1641 ,date_dim d3 1642 ,store 1643 ,item 1644 where 1645 d1.d_moy = 4 1646 and d1.d_year = 1998 1647 and d1.d_date_sk = ss_sold_date_sk 1648 and i_item_sk = ss_item_sk 1649 and s_store_sk = ss_store_sk 1650 and ss_customer_sk = sr_customer_sk 1651 and ss_item_sk = sr_item_sk 1652 and ss_ticket_number = sr_ticket_number 1653 and sr_returned_date_sk = d2.d_date_sk 1654 and d2.d_moy between 4 and 4 + 3 1655 and d2.d_year = 1998 1656 and sr_customer_sk = cs_bill_customer_sk 1657 and sr_item_sk = cs_item_sk 1658 and cs_sold_date_sk = d3.d_date_sk 1659 and d3.d_year in (1998,1998+1,1998+2) 1660 group by 1661 i_item_id 1662 ,i_item_desc 1663 ,s_store_id 1664 ,s_store_name 1665 order by 1666 i_item_id 1667 ,i_item_desc 1668 ,s_store_id 1669 ,s_store_name 1670 limit 100;`, 1671 }, 1672 { 1673 Query: ` 1674 -- start query 30 in stream 0 using template query30.tpl 1675 with customer_total_return as 1676 (select wr_returning_customer_sk as ctr_customer_sk 1677 ,ca_state as ctr_state, 1678 sum(wr_return_amt) as ctr_total_return 1679 from web_returns 1680 ,date_dim 1681 ,customer_address 1682 where wr_returned_date_sk = d_date_sk 1683 and d_year =2000 1684 and wr_returning_addr_sk = ca_address_sk 1685 group by wr_returning_customer_sk 1686 ,ca_state) 1687 select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag 1688 ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address 1689 ,c_last_review_date_sk,ctr_total_return 1690 from customer_total_return ctr1 1691 ,customer_address 1692 ,customer 1693 where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 1694 from customer_total_return ctr2 1695 where ctr1.ctr_state = ctr2.ctr_state) 1696 and ca_address_sk = c_current_addr_sk 1697 and ca_state = 'AR' 1698 and ctr1.ctr_customer_sk = c_customer_sk 1699 order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag 1700 ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address 1701 ,c_last_review_date_sk,ctr_total_return 1702 limit 100;`, 1703 }, 1704 { 1705 Query: ` 1706 -- start query 31 in stream 0 using template query31.tpl 1707 with ss as 1708 (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales 1709 from store_sales,date_dim,customer_address 1710 where ss_sold_date_sk = d_date_sk 1711 and ss_addr_sk=ca_address_sk 1712 group by ca_county,d_qoy, d_year), 1713 ws as 1714 (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales 1715 from web_sales,date_dim,customer_address 1716 where ws_sold_date_sk = d_date_sk 1717 and ws_bill_addr_sk=ca_address_sk 1718 group by ca_county,d_qoy, d_year) 1719 select 1720 ss1.ca_county 1721 ,ss1.d_year 1722 ,ws2.web_sales/ws1.web_sales web_q1_q2_increase 1723 ,ss2.store_sales/ss1.store_sales store_q1_q2_increase 1724 ,ws3.web_sales/ws2.web_sales web_q2_q3_increase 1725 ,ss3.store_sales/ss2.store_sales store_q2_q3_increase 1726 from 1727 ss ss1 1728 ,ss ss2 1729 ,ss ss3 1730 ,ws ws1 1731 ,ws ws2 1732 ,ws ws3 1733 where 1734 ss1.d_qoy = 1 1735 and ss1.d_year = 1999 1736 and ss1.ca_county = ss2.ca_county 1737 and ss2.d_qoy = 2 1738 and ss2.d_year = 1999 1739 and ss2.ca_county = ss3.ca_county 1740 and ss3.d_qoy = 3 1741 and ss3.d_year = 1999 1742 and ss1.ca_county = ws1.ca_county 1743 and ws1.d_qoy = 1 1744 and ws1.d_year = 1999 1745 and ws1.ca_county = ws2.ca_county 1746 and ws2.d_qoy = 2 1747 and ws2.d_year = 1999 1748 and ws1.ca_county = ws3.ca_county 1749 and ws3.d_qoy = 3 1750 and ws3.d_year =1999 1751 and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end 1752 > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end 1753 and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end 1754 > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end 1755 order by store_q2_q3_increase;`, 1756 }, 1757 { 1758 Query: ` 1759 -- start query 32 in stream 0 using template query32.tpl 1760 select sum(cs_ext_discount_amt) as "excess discount amount" 1761 from 1762 catalog_sales 1763 ,item 1764 ,date_dim 1765 where 1766 i_manufact_id = 722 1767 and i_item_sk = cs_item_sk 1768 and d_date between '2001-03-09' and 1769 (cast('2001-03-09' as date) + interval 90 day) 1770 and d_date_sk = cs_sold_date_sk 1771 and cs_ext_discount_amt 1772 > ( 1773 select 1774 1.3 * avg(cs_ext_discount_amt) 1775 from 1776 catalog_sales 1777 ,date_dim 1778 where 1779 cs_item_sk = i_item_sk 1780 and d_date between '2001-03-09' and 1781 (cast('2001-03-09' as date) + interval 90 day) 1782 and d_date_sk = cs_sold_date_sk 1783 ) 1784 limit 100;`, 1785 }, 1786 { 1787 Query: ` 1788 -- start query 33 in stream 0 using template query33.tpl 1789 with ss as ( 1790 select 1791 i_manufact_id,sum(ss_ext_sales_price) total_sales 1792 from 1793 store_sales, 1794 date_dim, 1795 customer_address, 1796 item 1797 where 1798 i_manufact_id in (select 1799 i_manufact_id 1800 from 1801 item 1802 where i_category in ('Books')) 1803 and ss_item_sk = i_item_sk 1804 and ss_sold_date_sk = d_date_sk 1805 and d_year = 2001 1806 and d_moy = 3 1807 and ss_addr_sk = ca_address_sk 1808 and ca_gmt_offset = -5 1809 group by i_manufact_id), 1810 cs as ( 1811 select 1812 i_manufact_id,sum(cs_ext_sales_price) total_sales 1813 from 1814 catalog_sales, 1815 date_dim, 1816 customer_address, 1817 item 1818 where 1819 i_manufact_id in (select 1820 i_manufact_id 1821 from 1822 item 1823 where i_category in ('Books')) 1824 and cs_item_sk = i_item_sk 1825 and cs_sold_date_sk = d_date_sk 1826 and d_year = 2001 1827 and d_moy = 3 1828 and cs_bill_addr_sk = ca_address_sk 1829 and ca_gmt_offset = -5 1830 group by i_manufact_id), 1831 ws as ( 1832 select 1833 i_manufact_id,sum(ws_ext_sales_price) total_sales 1834 from 1835 web_sales, 1836 date_dim, 1837 customer_address, 1838 item 1839 where 1840 i_manufact_id in (select 1841 i_manufact_id 1842 from 1843 item 1844 where i_category in ('Books')) 1845 and ws_item_sk = i_item_sk 1846 and ws_sold_date_sk = d_date_sk 1847 and d_year = 2001 1848 and d_moy = 3 1849 and ws_bill_addr_sk = ca_address_sk 1850 and ca_gmt_offset = -5 1851 group by i_manufact_id) 1852 select i_manufact_id ,sum(total_sales) total_sales 1853 from (select * from ss 1854 union all 1855 select * from cs 1856 union all 1857 select * from ws) tmp1 1858 group by i_manufact_id 1859 order by total_sales 1860 limit 100;`, 1861 }, 1862 { 1863 Query: ` 1864 -- start query 34 in stream 0 using template query34.tpl 1865 select c_last_name 1866 ,c_first_name 1867 ,c_salutation 1868 ,c_preferred_cust_flag 1869 ,ss_ticket_number 1870 ,cnt from 1871 (select ss_ticket_number 1872 ,ss_customer_sk 1873 ,count(*) cnt 1874 from store_sales,date_dim,store,household_demographics 1875 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 1876 and store_sales.ss_store_sk = store.s_store_sk 1877 and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk 1878 and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) 1879 and (household_demographics.hd_buy_potential = '1001-5000' or 1880 household_demographics.hd_buy_potential = '0-500') 1881 and household_demographics.hd_vehicle_count > 0 1882 and (case when household_demographics.hd_vehicle_count > 0 1883 then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count 1884 else null 1885 end) > 1.2 1886 and date_dim.d_year in (2000,2000+1,2000+2) 1887 and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County', 1888 'Williamson County','Williamson County','Williamson County','Williamson County') 1889 group by ss_ticket_number,ss_customer_sk) dn,customer 1890 where ss_customer_sk = c_customer_sk 1891 and cnt between 15 and 20 1892 order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number;`, 1893 }, 1894 { 1895 Query: ` 1896 -- start query 35 in stream 0 using template query35.tpl 1897 select 1898 ca_state, 1899 cd_gender, 1900 cd_marital_status, 1901 cd_dep_count, 1902 count(*) cnt1, 1903 avg(cd_dep_count), 1904 stddev_samp(cd_dep_count), 1905 sum(cd_dep_count), 1906 cd_dep_employed_count, 1907 count(*) cnt2, 1908 avg(cd_dep_employed_count), 1909 stddev_samp(cd_dep_employed_count), 1910 sum(cd_dep_employed_count), 1911 cd_dep_college_count, 1912 count(*) cnt3, 1913 avg(cd_dep_college_count), 1914 stddev_samp(cd_dep_college_count), 1915 sum(cd_dep_college_count) 1916 from 1917 customer c,customer_address ca,customer_demographics 1918 where 1919 c.c_current_addr_sk = ca.ca_address_sk and 1920 cd_demo_sk = c.c_current_cdemo_sk and 1921 exists (select * 1922 from store_sales,date_dim 1923 where c.c_customer_sk = ss_customer_sk and 1924 ss_sold_date_sk = d_date_sk and 1925 d_year = 1999 and 1926 d_qoy < 4) and 1927 (exists (select * 1928 from web_sales,date_dim 1929 where c.c_customer_sk = ws_bill_customer_sk and 1930 ws_sold_date_sk = d_date_sk and 1931 d_year = 1999 and 1932 d_qoy < 4) or 1933 exists (select * 1934 from catalog_sales,date_dim 1935 where c.c_customer_sk = cs_ship_customer_sk and 1936 cs_sold_date_sk = d_date_sk and 1937 d_year = 1999 and 1938 d_qoy < 4)) 1939 group by ca_state, 1940 cd_gender, 1941 cd_marital_status, 1942 cd_dep_count, 1943 cd_dep_employed_count, 1944 cd_dep_college_count 1945 order by ca_state, 1946 cd_gender, 1947 cd_marital_status, 1948 cd_dep_count, 1949 cd_dep_employed_count, 1950 cd_dep_college_count 1951 limit 100;`, 1952 }, 1953 { 1954 Query: ` 1955 -- start query 36 in stream 0 using template query36.tpl 1956 select 1957 sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin 1958 ,i_category 1959 ,i_class 1960 ,grouping(i_category)+grouping(i_class) as lochierarchy 1961 ,rank() over ( 1962 partition by grouping(i_category)+grouping(i_class), 1963 case when grouping(i_class) = 0 then i_category end 1964 order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent 1965 from 1966 store_sales 1967 ,date_dim d1 1968 ,item 1969 ,store 1970 where 1971 d1.d_year = 2000 1972 and d1.d_date_sk = ss_sold_date_sk 1973 and i_item_sk = ss_item_sk 1974 and s_store_sk = ss_store_sk 1975 and s_state in ('TN','TN','TN','TN', 1976 'TN','TN','TN','TN') 1977 group by rollup(i_category,i_class) 1978 order by 1979 lochierarchy desc 1980 ,case when lochierarchy = 0 then i_category end 1981 ,rank_within_parent 1982 limit 100;`, 1983 Skip: true, 1984 }, 1985 { 1986 Query: ` 1987 -- start query 37 in stream 0 using template query37.tpl 1988 select i_item_id 1989 ,i_item_desc 1990 ,i_current_price 1991 from item, inventory, date_dim, catalog_sales 1992 where i_current_price between 29 and 29 + 30 1993 and inv_item_sk = i_item_sk 1994 and d_date_sk=inv_date_sk 1995 and d_date between cast('2002-03-29' as date) and (cast('2002-03-29' as date) + interval 60 day) 1996 and i_manufact_id in (705,742,777,944) 1997 and inv_quantity_on_hand between 100 and 500 1998 and cs_item_sk = i_item_sk 1999 group by i_item_id,i_item_desc,i_current_price 2000 order by i_item_id 2001 limit 100;`, 2002 }, 2003 { 2004 Query: ` 2005 -- start query 38 in stream 0 using template query38.tpl 2006 select count(*) from ( 2007 select distinct c_last_name, c_first_name, d_date 2008 from store_sales, date_dim, customer 2009 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 2010 and store_sales.ss_customer_sk = customer.c_customer_sk 2011 and d_month_seq between 1189 and 1189 + 11 2012 intersect 2013 select distinct c_last_name, c_first_name, d_date 2014 from catalog_sales, date_dim, customer 2015 where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk 2016 and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk 2017 and d_month_seq between 1189 and 1189 + 11 2018 intersect 2019 select distinct c_last_name, c_first_name, d_date 2020 from web_sales, date_dim, customer 2021 where web_sales.ws_sold_date_sk = date_dim.d_date_sk 2022 and web_sales.ws_bill_customer_sk = customer.c_customer_sk 2023 and d_month_seq between 1189 and 1189 + 11 2024 ) hot_cust 2025 limit 100;`, 2026 }, 2027 { 2028 Query: ` 2029 -- start query 39 in stream 0 using template query39.tpl 2030 with inv as 2031 (select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy 2032 ,stdev,mean, case mean when 0 then null else stdev/mean end cov 2033 from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy 2034 ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean 2035 from inventory 2036 ,item 2037 ,warehouse 2038 ,date_dim 2039 where inv_item_sk = i_item_sk 2040 and inv_warehouse_sk = w_warehouse_sk 2041 and inv_date_sk = d_date_sk 2042 and d_year =2000 2043 group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo 2044 where case mean when 0 then 0 else stdev/mean end > 1) 2045 select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov 2046 ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov 2047 from inv inv1,inv inv2 2048 where inv1.i_item_sk = inv2.i_item_sk 2049 and inv1.w_warehouse_sk = inv2.w_warehouse_sk 2050 and inv1.d_moy=1 2051 and inv2.d_moy=1+1 2052 order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov 2053 ,inv2.d_moy,inv2.mean, inv2.cov 2054 ; 2055 with inv as 2056 (select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy 2057 ,stdev,mean, case mean when 0 then null else stdev/mean end cov 2058 from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy 2059 ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean 2060 from inventory 2061 ,item 2062 ,warehouse 2063 ,date_dim 2064 where inv_item_sk = i_item_sk 2065 and inv_warehouse_sk = w_warehouse_sk 2066 and inv_date_sk = d_date_sk 2067 and d_year =2000 2068 group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo 2069 where case mean when 0 then 0 else stdev/mean end > 1) 2070 select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov 2071 ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov 2072 from inv inv1,inv inv2 2073 where inv1.i_item_sk = inv2.i_item_sk 2074 and inv1.w_warehouse_sk = inv2.w_warehouse_sk 2075 and inv1.d_moy=1 2076 and inv2.d_moy=1+1 2077 and inv1.cov > 1.5 2078 order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov 2079 ,inv2.d_moy,inv2.mean, inv2.cov 2080 ;`, 2081 }, 2082 { 2083 Query: ` 2084 -- start query 40 in stream 0 using template query40.tpl 2085 select 2086 w_state 2087 ,i_item_id 2088 ,sum(case when (cast(d_date as date) < cast ('2001-05-02' as date)) 2089 then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before 2090 ,sum(case when (cast(d_date as date) >= cast ('2001-05-02' as date)) 2091 then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after 2092 from 2093 catalog_sales left outer join catalog_returns on 2094 (cs_order_number = cr_order_number 2095 and cs_item_sk = cr_item_sk) 2096 ,warehouse 2097 ,item 2098 ,date_dim 2099 where 2100 i_current_price between 0.99 and 1.49 2101 and i_item_sk = cs_item_sk 2102 and cs_warehouse_sk = w_warehouse_sk 2103 and cs_sold_date_sk = d_date_sk 2104 and d_date between (cast ('2001-05-02' as date) - interval 30 day) 2105 and (cast ('2001-05-02' as date) + interval 30 day) 2106 group by 2107 w_state,i_item_id 2108 order by w_state,i_item_id 2109 limit 100;`, 2110 }, 2111 { 2112 Query: ` 2113 -- start query 41 in stream 0 using template query41.tpl 2114 select distinct(i_product_name) 2115 from item i1 2116 where i_manufact_id between 704 and 704+40 2117 and (select count(*) as item_cnt 2118 from item 2119 where (i_manufact = i1.i_manufact and 2120 ((i_category = 'Women' and 2121 (i_color = 'forest' or i_color = 'lime') and 2122 (i_units = 'Pallet' or i_units = 'Pound') and 2123 (i_size = 'economy' or i_size = 'small') 2124 ) or 2125 (i_category = 'Women' and 2126 (i_color = 'navy' or i_color = 'slate') and 2127 (i_units = 'Gross' or i_units = 'Bunch') and 2128 (i_size = 'extra large' or i_size = 'petite') 2129 ) or 2130 (i_category = 'Men' and 2131 (i_color = 'powder' or i_color = 'sky') and 2132 (i_units = 'Dozen' or i_units = 'Lb') and 2133 (i_size = 'N/A' or i_size = 'large') 2134 ) or 2135 (i_category = 'Men' and 2136 (i_color = 'maroon' or i_color = 'smoke') and 2137 (i_units = 'Ounce' or i_units = 'Case') and 2138 (i_size = 'economy' or i_size = 'small') 2139 ))) or 2140 (i_manufact = i1.i_manufact and 2141 ((i_category = 'Women' and 2142 (i_color = 'dark' or i_color = 'aquamarine') and 2143 (i_units = 'Ton' or i_units = 'Tbl') and 2144 (i_size = 'economy' or i_size = 'small') 2145 ) or 2146 (i_category = 'Women' and 2147 (i_color = 'frosted' or i_color = 'plum') and 2148 (i_units = 'Dram' or i_units = 'Box') and 2149 (i_size = 'extra large' or i_size = 'petite') 2150 ) or 2151 (i_category = 'Men' and 2152 (i_color = 'papaya' or i_color = 'peach') and 2153 (i_units = 'Bundle' or i_units = 'Carton') and 2154 (i_size = 'N/A' or i_size = 'large') 2155 ) or 2156 (i_category = 'Men' and 2157 (i_color = 'firebrick' or i_color = 'sienna') and 2158 (i_units = 'Cup' or i_units = 'Each') and 2159 (i_size = 'economy' or i_size = 'small') 2160 )))) > 0 2161 order by i_product_name 2162 limit 100;`, 2163 }, 2164 { 2165 Query: ` 2166 -- start query 42 in stream 0 using template query42.tpl 2167 select dt.d_year 2168 ,item.i_category_id 2169 ,item.i_category 2170 ,sum(ss_ext_sales_price) 2171 from date_dim dt 2172 ,store_sales 2173 ,item 2174 where dt.d_date_sk = store_sales.ss_sold_date_sk 2175 and store_sales.ss_item_sk = item.i_item_sk 2176 and item.i_manager_id = 1 2177 and dt.d_moy=11 2178 and dt.d_year=1998 2179 group by dt.d_year 2180 ,item.i_category_id 2181 ,item.i_category 2182 order by sum(ss_ext_sales_price) desc,dt.d_year 2183 ,item.i_category_id 2184 ,item.i_category 2185 limit 100 ;`, 2186 }, 2187 { 2188 Query: ` 2189 -- start query 43 in stream 0 using template query43.tpl 2190 select s_store_name, s_store_id, 2191 sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, 2192 sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, 2193 sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, 2194 sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, 2195 sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, 2196 sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, 2197 sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales 2198 from date_dim, store_sales, store 2199 where d_date_sk = ss_sold_date_sk and 2200 s_store_sk = ss_store_sk and 2201 s_gmt_offset = -5 and 2202 d_year = 2000 2203 group by s_store_name, s_store_id 2204 order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales 2205 limit 100;`, 2206 }, 2207 { 2208 Query: ` 2209 -- start query 44 in stream 0 using template query44.tpl 2210 select asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing 2211 from(select * 2212 from (select item_sk,rank() over (order by rank_col asc) rnk 2213 from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col 2214 from store_sales ss1 2215 where ss_store_sk = 4 2216 group by ss_item_sk 2217 having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) rank_col 2218 from store_sales 2219 where ss_store_sk = 4 2220 and ss_hdemo_sk is null 2221 group by ss_store_sk))V1)V11 2222 where rnk < 11) asceding, 2223 (select * 2224 from (select item_sk,rank() over (order by rank_col desc) rnk 2225 from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col 2226 from store_sales ss1 2227 where ss_store_sk = 4 2228 group by ss_item_sk 2229 having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) rank_col 2230 from store_sales 2231 where ss_store_sk = 4 2232 and ss_hdemo_sk is null 2233 group by ss_store_sk))V2)V21 2234 where rnk < 11) descending, 2235 item i1, 2236 item i2 2237 where asceding.rnk = descending.rnk 2238 and i1.i_item_sk=asceding.item_sk 2239 and i2.i_item_sk=descending.item_sk 2240 order by asceding.rnk 2241 limit 100;`, 2242 }, 2243 { 2244 Query: ` 2245 -- start query 45 in stream 0 using template query45.tpl 2246 select ca_zip, ca_city, sum(ws_sales_price) 2247 from web_sales, customer, customer_address, date_dim, item 2248 where ws_bill_customer_sk = c_customer_sk 2249 and c_current_addr_sk = ca_address_sk 2250 and ws_item_sk = i_item_sk 2251 and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') 2252 or 2253 i_item_id in (select i_item_id 2254 from item 2255 where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) 2256 ) 2257 ) 2258 and ws_sold_date_sk = d_date_sk 2259 and d_qoy = 1 and d_year = 2000 2260 group by ca_zip, ca_city 2261 order by ca_zip, ca_city 2262 limit 100;`, 2263 }, 2264 { 2265 Query: ` 2266 -- start query 46 in stream 0 using template query46.tpl 2267 select c_last_name 2268 ,c_first_name 2269 ,ca_city 2270 ,bought_city 2271 ,ss_ticket_number 2272 ,amt,profit 2273 from 2274 (select ss_ticket_number 2275 ,ss_customer_sk 2276 ,ca_city bought_city 2277 ,sum(ss_coupon_amt) amt 2278 ,sum(ss_net_profit) profit 2279 from store_sales,date_dim,store,household_demographics,customer_address 2280 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 2281 and store_sales.ss_store_sk = store.s_store_sk 2282 and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk 2283 and store_sales.ss_addr_sk = customer_address.ca_address_sk 2284 and (household_demographics.hd_dep_count = 8 or 2285 household_demographics.hd_vehicle_count= 0) 2286 and date_dim.d_dow in (6,0) 2287 and date_dim.d_year in (2000,2000+1,2000+2) 2288 and store.s_city in ('Midway','Fairview','Fairview','Fairview','Fairview') 2289 group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr 2290 where ss_customer_sk = c_customer_sk 2291 and customer.c_current_addr_sk = current_addr.ca_address_sk 2292 and current_addr.ca_city <> bought_city 2293 order by c_last_name 2294 ,c_first_name 2295 ,ca_city 2296 ,bought_city 2297 ,ss_ticket_number 2298 limit 100;`, 2299 }, 2300 { 2301 Query: ` 2302 -- start query 47 in stream 0 using template query47.tpl 2303 with v1 as( 2304 select i_category, i_brand, 2305 s_store_name, s_company_name, 2306 d_year, d_moy, 2307 sum(ss_sales_price) sum_sales, 2308 avg(sum(ss_sales_price)) over 2309 (partition by i_category, i_brand, 2310 s_store_name, s_company_name, d_year) 2311 avg_monthly_sales, 2312 rank() over 2313 (partition by i_category, i_brand, 2314 s_store_name, s_company_name 2315 order by d_year, d_moy) rn 2316 from item, store_sales, date_dim, store 2317 where ss_item_sk = i_item_sk and 2318 ss_sold_date_sk = d_date_sk and 2319 ss_store_sk = s_store_sk and 2320 ( 2321 d_year = 2000 or 2322 ( d_year = 2000-1 and d_moy =12) or 2323 ( d_year = 2000+1 and d_moy =1) 2324 ) 2325 group by i_category, i_brand, 2326 s_store_name, s_company_name, 2327 d_year, d_moy), 2328 v2 as( 2329 select v1.s_store_name, v1.s_company_name 2330 ,v1.d_year 2331 ,v1.avg_monthly_sales 2332 ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum 2333 from v1, v1 v1_lag, v1 v1_lead 2334 where v1.i_category = v1_lag.i_category and 2335 v1.i_category = v1_lead.i_category and 2336 v1.i_brand = v1_lag.i_brand and 2337 v1.i_brand = v1_lead.i_brand and 2338 v1.s_store_name = v1_lag.s_store_name and 2339 v1.s_store_name = v1_lead.s_store_name and 2340 v1.s_company_name = v1_lag.s_company_name and 2341 v1.s_company_name = v1_lead.s_company_name and 2342 v1.rn = v1_lag.rn + 1 and 2343 v1.rn = v1_lead.rn - 1) 2344 select * 2345 from v2 2346 where d_year = 2000 and 2347 avg_monthly_sales > 0 and 2348 case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 2349 order by sum_sales - avg_monthly_sales, nsum 2350 limit 100;`, 2351 }, 2352 { 2353 Query: ` 2354 -- start query 48 in stream 0 using template query48.tpl 2355 select sum (ss_quantity) 2356 from store_sales, store, customer_demographics, customer_address, date_dim 2357 where s_store_sk = ss_store_sk 2358 and ss_sold_date_sk = d_date_sk and d_year = 2001 2359 and 2360 ( 2361 ( 2362 cd_demo_sk = ss_cdemo_sk 2363 and 2364 cd_marital_status = 'S' 2365 and 2366 cd_education_status = 'Secondary' 2367 and 2368 ss_sales_price between 100.00 and 150.00 2369 ) 2370 or 2371 ( 2372 cd_demo_sk = ss_cdemo_sk 2373 and 2374 cd_marital_status = 'M' 2375 and 2376 cd_education_status = '2 yr Degree' 2377 and 2378 ss_sales_price between 50.00 and 100.00 2379 ) 2380 or 2381 ( 2382 cd_demo_sk = ss_cdemo_sk 2383 and 2384 cd_marital_status = 'D' 2385 and 2386 cd_education_status = 'Advanced Degree' 2387 and 2388 ss_sales_price between 150.00 and 200.00 2389 ) 2390 ) 2391 and 2392 ( 2393 ( 2394 ss_addr_sk = ca_address_sk 2395 and 2396 ca_country = 'United States' 2397 and 2398 ca_state in ('ND', 'NY', 'SD') 2399 and ss_net_profit between 0 and 2000 2400 ) 2401 or 2402 (ss_addr_sk = ca_address_sk 2403 and 2404 ca_country = 'United States' 2405 and 2406 ca_state in ('MD', 'GA', 'KS') 2407 and ss_net_profit between 150 and 3000 2408 ) 2409 or 2410 (ss_addr_sk = ca_address_sk 2411 and 2412 ca_country = 'United States' 2413 and 2414 ca_state in ('CO', 'MN', 'NC') 2415 and ss_net_profit between 50 and 25000 2416 ) 2417 ) 2418 ;`, 2419 }, 2420 { 2421 Query: ` 2422 -- start query 49 in stream 0 using template query49.tpl 2423 select channel, item, return_ratio, return_rank, currency_rank from 2424 (select 2425 'web' as channel 2426 ,web.item 2427 ,web.return_ratio 2428 ,web.return_rank 2429 ,web.currency_rank 2430 from ( 2431 select 2432 item 2433 ,return_ratio 2434 ,currency_ratio 2435 ,rank() over (order by return_ratio) as return_rank 2436 ,rank() over (order by currency_ratio) as currency_rank 2437 from 2438 ( select ws.ws_item_sk as item 2439 ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ 2440 cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio 2441 ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ 2442 cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio 2443 from 2444 web_sales ws left outer join web_returns wr 2445 on (ws.ws_order_number = wr.wr_order_number and 2446 ws.ws_item_sk = wr.wr_item_sk) 2447 ,date_dim 2448 where 2449 wr.wr_return_amt > 10000 2450 and ws.ws_net_profit > 1 2451 and ws.ws_net_paid > 0 2452 and ws.ws_quantity > 0 2453 and ws_sold_date_sk = d_date_sk 2454 and d_year = 1998 2455 and d_moy = 11 2456 group by ws.ws_item_sk 2457 ) in_web 2458 ) web 2459 where 2460 ( 2461 web.return_rank <= 10 2462 or 2463 web.currency_rank <= 10 2464 ) 2465 union 2466 select 2467 'catalog' as channel 2468 ,catalog.item 2469 ,catalog.return_ratio 2470 ,catalog.return_rank 2471 ,catalog.currency_rank 2472 from ( 2473 select 2474 item 2475 ,return_ratio 2476 ,currency_ratio 2477 ,rank() over (order by return_ratio) as return_rank 2478 ,rank() over (order by currency_ratio) as currency_rank 2479 from 2480 ( select 2481 cs.cs_item_sk as item 2482 ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ 2483 cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio 2484 ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ 2485 cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio 2486 from 2487 catalog_sales cs left outer join catalog_returns cr 2488 on (cs.cs_order_number = cr.cr_order_number and 2489 cs.cs_item_sk = cr.cr_item_sk) 2490 ,date_dim 2491 where 2492 cr.cr_return_amount > 10000 2493 and cs.cs_net_profit > 1 2494 and cs.cs_net_paid > 0 2495 and cs.cs_quantity > 0 2496 and cs_sold_date_sk = d_date_sk 2497 and d_year = 1998 2498 and d_moy = 11 2499 group by cs.cs_item_sk 2500 ) in_cat 2501 ) catalog 2502 where 2503 ( 2504 catalog.return_rank <= 10 2505 or 2506 catalog.currency_rank <=10 2507 ) 2508 union 2509 select 2510 'store' as channel 2511 ,store.item 2512 ,store.return_ratio 2513 ,store.return_rank 2514 ,store.currency_rank 2515 from ( 2516 select 2517 item 2518 ,return_ratio 2519 ,currency_ratio 2520 ,rank() over (order by return_ratio) as return_rank 2521 ,rank() over (order by currency_ratio) as currency_rank 2522 from 2523 ( select sts.ss_item_sk as item 2524 ,(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 2525 ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio 2526 from 2527 store_sales sts left outer join store_returns sr 2528 on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) 2529 ,date_dim 2530 where 2531 sr.sr_return_amt > 10000 2532 and sts.ss_net_profit > 1 2533 and sts.ss_net_paid > 0 2534 and sts.ss_quantity > 0 2535 and ss_sold_date_sk = d_date_sk 2536 and d_year = 1998 2537 and d_moy = 11 2538 group by sts.ss_item_sk 2539 ) in_store 2540 ) store 2541 where ( 2542 store.return_rank <= 10 2543 or 2544 store.currency_rank <= 10 2545 ) 2546 ) 2547 order by 1,4,5,2 2548 limit 100;`, 2549 }, 2550 { 2551 Query: ` 2552 -- start query 50 in stream 0 using template query50.tpl 2553 select 2554 s_store_name 2555 ,s_company_id 2556 ,s_street_number 2557 ,s_street_name 2558 ,s_street_type 2559 ,s_suite_number 2560 ,s_city 2561 ,s_county 2562 ,s_state 2563 ,s_zip 2564 ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" 2565 ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and 2566 (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" 2567 ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and 2568 (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" 2569 ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and 2570 (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" 2571 ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as ">120 days" 2572 from 2573 store_sales 2574 ,store_returns 2575 ,store 2576 ,date_dim d1 2577 ,date_dim d2 2578 where 2579 d2.d_year = 2001 2580 and d2.d_moy = 8 2581 and ss_ticket_number = sr_ticket_number 2582 and ss_item_sk = sr_item_sk 2583 and ss_sold_date_sk = d1.d_date_sk 2584 and sr_returned_date_sk = d2.d_date_sk 2585 and ss_customer_sk = sr_customer_sk 2586 and ss_store_sk = s_store_sk 2587 group by 2588 s_store_name 2589 ,s_company_id 2590 ,s_street_number 2591 ,s_street_name 2592 ,s_street_type 2593 ,s_suite_number 2594 ,s_city 2595 ,s_county 2596 ,s_state 2597 ,s_zip 2598 order by s_store_name 2599 ,s_company_id 2600 ,s_street_number 2601 ,s_street_name 2602 ,s_street_type 2603 ,s_suite_number 2604 ,s_city 2605 ,s_county 2606 ,s_state 2607 ,s_zip 2608 limit 100;`, 2609 }, 2610 { 2611 Query: ` 2612 -- start query 51 in stream 0 using template query51.tpl 2613 WITH web_v1 as ( 2614 select 2615 ws_item_sk item_sk, d_date, 2616 sum(sum(ws_sales_price)) 2617 over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales 2618 from web_sales 2619 ,date_dim 2620 where ws_sold_date_sk=d_date_sk 2621 and d_month_seq between 1212 and 1212+11 2622 and ws_item_sk is not NULL 2623 group by ws_item_sk, d_date), 2624 store_v1 as ( 2625 select 2626 ss_item_sk item_sk, d_date, 2627 sum(sum(ss_sales_price)) 2628 over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales 2629 from store_sales 2630 ,date_dim 2631 where ss_sold_date_sk=d_date_sk 2632 and d_month_seq between 1212 and 1212+11 2633 and ss_item_sk is not NULL 2634 group by ss_item_sk, d_date) 2635 select * 2636 from (select item_sk 2637 ,d_date 2638 ,web_sales 2639 ,store_sales 2640 ,max(web_sales) 2641 over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative 2642 ,max(store_sales) 2643 over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative 2644 from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk 2645 ,case when web.d_date is not null then web.d_date else store.d_date end d_date 2646 ,web.cume_sales web_sales 2647 ,store.cume_sales store_sales 2648 from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk 2649 and web.d_date = store.d_date) 2650 )x )y 2651 where web_cumulative > store_cumulative 2652 order by item_sk 2653 ,d_date 2654 limit 100;`, 2655 }, 2656 { 2657 Query: ` 2658 -- start query 52 in stream 0 using template query52.tpl 2659 select dt.d_year 2660 ,item.i_brand_id brand_id 2661 ,item.i_brand brand 2662 ,sum(ss_ext_sales_price) ext_price 2663 from date_dim dt 2664 ,store_sales 2665 ,item 2666 where dt.d_date_sk = store_sales.ss_sold_date_sk 2667 and store_sales.ss_item_sk = item.i_item_sk 2668 and item.i_manager_id = 1 2669 and dt.d_moy=12 2670 and dt.d_year=2000 2671 group by dt.d_year 2672 ,item.i_brand 2673 ,item.i_brand_id 2674 order by dt.d_year 2675 ,ext_price desc 2676 ,brand_id 2677 limit 100 ;`, 2678 }, 2679 { 2680 Query: ` 2681 -- start query 53 in stream 0 using template query53.tpl 2682 select * from 2683 (select i_manufact_id, 2684 sum(ss_sales_price) sum_sales, 2685 avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales 2686 from item, store_sales, date_dim, store 2687 where ss_item_sk = i_item_sk and 2688 ss_sold_date_sk = d_date_sk and 2689 ss_store_sk = s_store_sk and 2690 d_month_seq in (1186,1186+1,1186+2,1186+3,1186+4,1186+5,1186+6,1186+7,1186+8,1186+9,1186+10,1186+11) and 2691 ((i_category in ('Books','Children','Electronics') and 2692 i_class in ('personal','portable','reference','self-help') and 2693 i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', 2694 'exportiunivamalg #9','scholaramalgamalg #9')) 2695 or(i_category in ('Women','Music','Men') and 2696 i_class in ('accessories','classical','fragrances','pants') and 2697 i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', 2698 'importoamalg #1'))) 2699 group by i_manufact_id, d_qoy ) tmp1 2700 where case when avg_quarterly_sales > 0 2701 then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales 2702 else null end > 0.1 2703 order by avg_quarterly_sales, 2704 sum_sales, 2705 i_manufact_id 2706 limit 100;`, 2707 }, 2708 { 2709 Query: ` 2710 -- start query 54 in stream 0 using template query54.tpl 2711 with my_customers as ( 2712 select distinct c_customer_sk 2713 , c_current_addr_sk 2714 from 2715 ( select cs_sold_date_sk sold_date_sk, 2716 cs_bill_customer_sk customer_sk, 2717 cs_item_sk item_sk 2718 from catalog_sales 2719 union all 2720 select ws_sold_date_sk sold_date_sk, 2721 ws_bill_customer_sk customer_sk, 2722 ws_item_sk item_sk 2723 from web_sales 2724 ) cs_or_ws_sales, 2725 item, 2726 date_dim, 2727 customer 2728 where sold_date_sk = d_date_sk 2729 and item_sk = i_item_sk 2730 and i_category = 'Music' 2731 and i_class = 'country' 2732 and c_customer_sk = cs_or_ws_sales.customer_sk 2733 and d_moy = 1 2734 and d_year = 1999 2735 ) 2736 , my_revenue as ( 2737 select c_customer_sk, 2738 sum(ss_ext_sales_price) as revenue 2739 from my_customers, 2740 store_sales, 2741 customer_address, 2742 store, 2743 date_dim 2744 where c_current_addr_sk = ca_address_sk 2745 and ca_county = s_county 2746 and ca_state = s_state 2747 and ss_sold_date_sk = d_date_sk 2748 and c_customer_sk = ss_customer_sk 2749 and d_month_seq between (select distinct d_month_seq+1 2750 from date_dim where d_year = 1999 and d_moy = 1) 2751 and (select distinct d_month_seq+3 2752 from date_dim where d_year = 1999 and d_moy = 1) 2753 group by c_customer_sk 2754 ) 2755 , segments as 2756 (select cast((revenue/50) as int) as segment 2757 from my_revenue 2758 ) 2759 select segment, count(*) as num_customers, segment*50 as segment_base 2760 from segments 2761 group by segment 2762 order by segment, num_customers 2763 limit 100;`, 2764 }, 2765 { 2766 Query: ` 2767 -- start query 55 in stream 0 using template query55.tpl 2768 select i_brand_id brand_id, i_brand brand, 2769 sum(ss_ext_sales_price) ext_price 2770 from date_dim, store_sales, item 2771 where d_date_sk = ss_sold_date_sk 2772 and ss_item_sk = i_item_sk 2773 and i_manager_id=52 2774 and d_moy=11 2775 and d_year=2000 2776 group by i_brand, i_brand_id 2777 order by ext_price desc, i_brand_id 2778 limit 100 ;`, 2779 }, 2780 { 2781 Query: ` 2782 -- start query 56 in stream 0 using template query56.tpl 2783 with ss as ( 2784 select i_item_id,sum(ss_ext_sales_price) total_sales 2785 from 2786 store_sales, 2787 date_dim, 2788 customer_address, 2789 item 2790 where i_item_id in (select 2791 i_item_id 2792 from item 2793 where i_color in ('powder','orchid','pink')) 2794 and ss_item_sk = i_item_sk 2795 and ss_sold_date_sk = d_date_sk 2796 and d_year = 2000 2797 and d_moy = 3 2798 and ss_addr_sk = ca_address_sk 2799 and ca_gmt_offset = -6 2800 group by i_item_id), 2801 cs as ( 2802 select i_item_id,sum(cs_ext_sales_price) total_sales 2803 from 2804 catalog_sales, 2805 date_dim, 2806 customer_address, 2807 item 2808 where 2809 i_item_id in (select 2810 i_item_id 2811 from item 2812 where i_color in ('powder','orchid','pink')) 2813 and cs_item_sk = i_item_sk 2814 and cs_sold_date_sk = d_date_sk 2815 and d_year = 2000 2816 and d_moy = 3 2817 and cs_bill_addr_sk = ca_address_sk 2818 and ca_gmt_offset = -6 2819 group by i_item_id), 2820 ws as ( 2821 select i_item_id,sum(ws_ext_sales_price) total_sales 2822 from 2823 web_sales, 2824 date_dim, 2825 customer_address, 2826 item 2827 where 2828 i_item_id in (select 2829 i_item_id 2830 from item 2831 where i_color in ('powder','orchid','pink')) 2832 and ws_item_sk = i_item_sk 2833 and ws_sold_date_sk = d_date_sk 2834 and d_year = 2000 2835 and d_moy = 3 2836 and ws_bill_addr_sk = ca_address_sk 2837 and ca_gmt_offset = -6 2838 group by i_item_id) 2839 select i_item_id ,sum(total_sales) total_sales 2840 from (select * from ss 2841 union all 2842 select * from cs 2843 union all 2844 select * from ws) tmp1 2845 group by i_item_id 2846 order by total_sales, 2847 i_item_id 2848 limit 100;`, 2849 }, 2850 { 2851 Query: ` 2852 -- start query 57 in stream 0 using template query57.tpl 2853 with v1 as( 2854 select i_category, i_brand, 2855 cc_name, 2856 d_year, d_moy, 2857 sum(cs_sales_price) sum_sales, 2858 avg(sum(cs_sales_price)) over 2859 (partition by i_category, i_brand, 2860 cc_name, d_year) 2861 avg_monthly_sales, 2862 rank() over 2863 (partition by i_category, i_brand, 2864 cc_name 2865 order by d_year, d_moy) rn 2866 from item, catalog_sales, date_dim, call_center 2867 where cs_item_sk = i_item_sk and 2868 cs_sold_date_sk = d_date_sk and 2869 cc_call_center_sk= cs_call_center_sk and 2870 ( 2871 d_year = 2001 or 2872 ( d_year = 2001-1 and d_moy =12) or 2873 ( d_year = 2001+1 and d_moy =1) 2874 ) 2875 group by i_category, i_brand, 2876 cc_name , d_year, d_moy), 2877 v2 as( 2878 select v1.i_category, v1.i_brand, v1.cc_name 2879 ,v1.d_year 2880 ,v1.avg_monthly_sales 2881 ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum 2882 from v1, v1 v1_lag, v1 v1_lead 2883 where v1.i_category = v1_lag.i_category and 2884 v1.i_category = v1_lead.i_category and 2885 v1.i_brand = v1_lag.i_brand and 2886 v1.i_brand = v1_lead.i_brand and 2887 v1. cc_name = v1_lag. cc_name and 2888 v1. cc_name = v1_lead. cc_name and 2889 v1.rn = v1_lag.rn + 1 and 2890 v1.rn = v1_lead.rn - 1) 2891 select * 2892 from v2 2893 where d_year = 2001 and 2894 avg_monthly_sales > 0 and 2895 case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 2896 order by sum_sales - avg_monthly_sales, avg_monthly_sales 2897 limit 100;`, 2898 }, 2899 { 2900 Query: ` 2901 -- start query 58 in stream 0 using template query58.tpl 2902 with ss_items as 2903 (select i_item_id item_id 2904 ,sum(ss_ext_sales_price) ss_item_rev 2905 from store_sales 2906 ,item 2907 ,date_dim 2908 where ss_item_sk = i_item_sk 2909 and d_date in (select d_date 2910 from date_dim 2911 where d_week_seq = (select d_week_seq 2912 from date_dim 2913 where d_date = '2001-06-16')) 2914 and ss_sold_date_sk = d_date_sk 2915 group by i_item_id), 2916 cs_items as 2917 (select i_item_id item_id 2918 ,sum(cs_ext_sales_price) cs_item_rev 2919 from catalog_sales 2920 ,item 2921 ,date_dim 2922 where cs_item_sk = i_item_sk 2923 and d_date in (select d_date 2924 from date_dim 2925 where d_week_seq = (select d_week_seq 2926 from date_dim 2927 where d_date = '2001-06-16')) 2928 and cs_sold_date_sk = d_date_sk 2929 group by i_item_id), 2930 ws_items as 2931 (select i_item_id item_id 2932 ,sum(ws_ext_sales_price) ws_item_rev 2933 from web_sales 2934 ,item 2935 ,date_dim 2936 where ws_item_sk = i_item_sk 2937 and d_date in (select d_date 2938 from date_dim 2939 where d_week_seq =(select d_week_seq 2940 from date_dim 2941 where d_date = '2001-06-16')) 2942 and ws_sold_date_sk = d_date_sk 2943 group by i_item_id) 2944 select ss_items.item_id 2945 ,ss_item_rev 2946 ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev 2947 ,cs_item_rev 2948 ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev 2949 ,ws_item_rev 2950 ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev 2951 ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average 2952 from ss_items,cs_items,ws_items 2953 where ss_items.item_id=cs_items.item_id 2954 and ss_items.item_id=ws_items.item_id 2955 and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev 2956 and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev 2957 and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev 2958 and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev 2959 and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev 2960 and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev 2961 order by item_id 2962 ,ss_item_rev 2963 limit 100;`, 2964 }, 2965 { 2966 Query: ` 2967 -- start query 59 in stream 0 using template query59.tpl 2968 with wss as 2969 (select d_week_seq, 2970 ss_store_sk, 2971 sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, 2972 sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, 2973 sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, 2974 sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, 2975 sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, 2976 sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, 2977 sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales 2978 from store_sales,date_dim 2979 where d_date_sk = ss_sold_date_sk 2980 group by d_week_seq,ss_store_sk 2981 ) 2982 select s_store_name1,s_store_id1,d_week_seq1 2983 ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 2984 ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 2985 ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 2986 from 2987 (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 2988 ,s_store_id s_store_id1,sun_sales sun_sales1 2989 ,mon_sales mon_sales1,tue_sales tue_sales1 2990 ,wed_sales wed_sales1,thu_sales thu_sales1 2991 ,fri_sales fri_sales1,sat_sales sat_sales1 2992 from wss,store,date_dim d 2993 where d.d_week_seq = wss.d_week_seq and 2994 ss_store_sk = s_store_sk and 2995 d_month_seq between 1195 and 1195 + 11) y, 2996 (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 2997 ,s_store_id s_store_id2,sun_sales sun_sales2 2998 ,mon_sales mon_sales2,tue_sales tue_sales2 2999 ,wed_sales wed_sales2,thu_sales thu_sales2 3000 ,fri_sales fri_sales2,sat_sales sat_sales2 3001 from wss,store,date_dim d 3002 where d.d_week_seq = wss.d_week_seq and 3003 ss_store_sk = s_store_sk and 3004 d_month_seq between 1195+ 12 and 1195 + 23) x 3005 where s_store_id1=s_store_id2 3006 and d_week_seq1=d_week_seq2-52 3007 order by s_store_name1,s_store_id1,d_week_seq1 3008 limit 100;`, 3009 }, 3010 { 3011 Query: ` 3012 -- start query 60 in stream 0 using template query60.tpl 3013 with ss as ( 3014 select 3015 i_item_id,sum(ss_ext_sales_price) total_sales 3016 from 3017 store_sales, 3018 date_dim, 3019 customer_address, 3020 item 3021 where 3022 i_item_id in (select 3023 i_item_id 3024 from 3025 item 3026 where i_category in ('Jewelry')) 3027 and ss_item_sk = i_item_sk 3028 and ss_sold_date_sk = d_date_sk 3029 and d_year = 2000 3030 and d_moy = 10 3031 and ss_addr_sk = ca_address_sk 3032 and ca_gmt_offset = -5 3033 group by i_item_id), 3034 cs as ( 3035 select 3036 i_item_id,sum(cs_ext_sales_price) total_sales 3037 from 3038 catalog_sales, 3039 date_dim, 3040 customer_address, 3041 item 3042 where 3043 i_item_id in (select 3044 i_item_id 3045 from 3046 item 3047 where i_category in ('Jewelry')) 3048 and cs_item_sk = i_item_sk 3049 and cs_sold_date_sk = d_date_sk 3050 and d_year = 2000 3051 and d_moy = 10 3052 and cs_bill_addr_sk = ca_address_sk 3053 and ca_gmt_offset = -5 3054 group by i_item_id), 3055 ws as ( 3056 select 3057 i_item_id,sum(ws_ext_sales_price) total_sales 3058 from 3059 web_sales, 3060 date_dim, 3061 customer_address, 3062 item 3063 where 3064 i_item_id in (select 3065 i_item_id 3066 from 3067 item 3068 where i_category in ('Jewelry')) 3069 and ws_item_sk = i_item_sk 3070 and ws_sold_date_sk = d_date_sk 3071 and d_year = 2000 3072 and d_moy = 10 3073 and ws_bill_addr_sk = ca_address_sk 3074 and ca_gmt_offset = -5 3075 group by i_item_id) 3076 select 3077 i_item_id 3078 ,sum(total_sales) total_sales 3079 from (select * from ss 3080 union all 3081 select * from cs 3082 union all 3083 select * from ws) tmp1 3084 group by i_item_id 3085 order by i_item_id 3086 ,total_sales 3087 limit 100;`, 3088 }, 3089 { 3090 Query: ` 3091 -- start query 61 in stream 0 using template query61.tpl 3092 select promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 3093 from 3094 (select sum(ss_ext_sales_price) promotions 3095 from store_sales 3096 ,store 3097 ,promotion 3098 ,date_dim 3099 ,customer 3100 ,customer_address 3101 ,item 3102 where ss_sold_date_sk = d_date_sk 3103 and ss_store_sk = s_store_sk 3104 and ss_promo_sk = p_promo_sk 3105 and ss_customer_sk= c_customer_sk 3106 and ca_address_sk = c_current_addr_sk 3107 and ss_item_sk = i_item_sk 3108 and ca_gmt_offset = -7 3109 and i_category = 'Home' 3110 and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') 3111 and s_gmt_offset = -7 3112 and d_year = 2000 3113 and d_moy = 12) promotional_sales, 3114 (select sum(ss_ext_sales_price) total 3115 from store_sales 3116 ,store 3117 ,date_dim 3118 ,customer 3119 ,customer_address 3120 ,item 3121 where ss_sold_date_sk = d_date_sk 3122 and ss_store_sk = s_store_sk 3123 and ss_customer_sk= c_customer_sk 3124 and ca_address_sk = c_current_addr_sk 3125 and ss_item_sk = i_item_sk 3126 and ca_gmt_offset = -7 3127 and i_category = 'Home' 3128 and s_gmt_offset = -7 3129 and d_year = 2000 3130 and d_moy = 12) all_sales 3131 order by promotions, total 3132 limit 100;`, 3133 }, 3134 { 3135 Query: ` 3136 -- start query 62 in stream 0 using template query62.tpl 3137 select 3138 substr(w_warehouse_name,1,20) 3139 ,sm_type 3140 ,web_name 3141 ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" 3142 ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and 3143 (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" 3144 ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and 3145 (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" 3146 ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and 3147 (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" 3148 ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as ">120 days" 3149 from 3150 web_sales 3151 ,warehouse 3152 ,ship_mode 3153 ,web_site 3154 ,date_dim 3155 where 3156 d_month_seq between 1223 and 1223 + 11 3157 and ws_ship_date_sk = d_date_sk 3158 and ws_warehouse_sk = w_warehouse_sk 3159 and ws_ship_mode_sk = sm_ship_mode_sk 3160 and ws_web_site_sk = web_site_sk 3161 group by 3162 substr(w_warehouse_name,1,20) 3163 ,sm_type 3164 ,web_name 3165 order by substr(w_warehouse_name,1,20) 3166 ,sm_type 3167 ,web_name 3168 limit 100;`, 3169 }, 3170 { 3171 Query: ` 3172 -- start query 63 in stream 0 using template query63.tpl 3173 select * 3174 from (select i_manager_id 3175 ,sum(ss_sales_price) sum_sales 3176 ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales 3177 from item 3178 ,store_sales 3179 ,date_dim 3180 ,store 3181 where ss_item_sk = i_item_sk 3182 and ss_sold_date_sk = d_date_sk 3183 and ss_store_sk = s_store_sk 3184 and d_month_seq in (1222,1222+1,1222+2,1222+3,1222+4,1222+5,1222+6,1222+7,1222+8,1222+9,1222+10,1222+11) 3185 and (( i_category in ('Books','Children','Electronics') 3186 and i_class in ('personal','portable','reference','self-help') 3187 and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', 3188 'exportiunivamalg #9','scholaramalgamalg #9')) 3189 or( i_category in ('Women','Music','Men') 3190 and i_class in ('accessories','classical','fragrances','pants') 3191 and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', 3192 'importoamalg #1'))) 3193 group by i_manager_id, d_moy) tmp1 3194 where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 3195 order by i_manager_id 3196 ,avg_monthly_sales 3197 ,sum_sales 3198 limit 100;`, 3199 }, 3200 { 3201 Query: ` 3202 -- start query 64 in stream 0 using template query64.tpl 3203 with cs_ui as 3204 (select cs_item_sk 3205 ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund 3206 from catalog_sales 3207 ,catalog_returns 3208 where cs_item_sk = cr_item_sk 3209 and cs_order_number = cr_order_number 3210 group by cs_item_sk 3211 having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), 3212 cross_sales as 3213 (select i_product_name product_name 3214 ,i_item_sk item_sk 3215 ,s_store_name store_name 3216 ,s_zip store_zip 3217 ,ad1.ca_street_number b_street_number 3218 ,ad1.ca_street_name b_street_name 3219 ,ad1.ca_city b_city 3220 ,ad1.ca_zip b_zip 3221 ,ad2.ca_street_number c_street_number 3222 ,ad2.ca_street_name c_street_name 3223 ,ad2.ca_city c_city 3224 ,ad2.ca_zip c_zip 3225 ,d1.d_year as syear 3226 ,d2.d_year as fsyear 3227 ,d3.d_year s2year 3228 ,count(*) cnt 3229 ,sum(ss_wholesale_cost) s1 3230 ,sum(ss_list_price) s2 3231 ,sum(ss_coupon_amt) s3 3232 FROM store_sales 3233 ,store_returns 3234 ,cs_ui 3235 ,date_dim d1 3236 ,date_dim d2 3237 ,date_dim d3 3238 ,store 3239 ,customer 3240 ,customer_demographics cd1 3241 ,customer_demographics cd2 3242 ,promotion 3243 ,household_demographics hd1 3244 ,household_demographics hd2 3245 ,customer_address ad1 3246 ,customer_address ad2 3247 ,income_band ib1 3248 ,income_band ib2 3249 ,item 3250 WHERE ss_store_sk = s_store_sk AND 3251 ss_sold_date_sk = d1.d_date_sk AND 3252 ss_customer_sk = c_customer_sk AND 3253 ss_cdemo_sk= cd1.cd_demo_sk AND 3254 ss_hdemo_sk = hd1.hd_demo_sk AND 3255 ss_addr_sk = ad1.ca_address_sk and 3256 ss_item_sk = i_item_sk and 3257 ss_item_sk = sr_item_sk and 3258 ss_ticket_number = sr_ticket_number and 3259 ss_item_sk = cs_ui.cs_item_sk and 3260 c_current_cdemo_sk = cd2.cd_demo_sk AND 3261 c_current_hdemo_sk = hd2.hd_demo_sk AND 3262 c_current_addr_sk = ad2.ca_address_sk and 3263 c_first_sales_date_sk = d2.d_date_sk and 3264 c_first_shipto_date_sk = d3.d_date_sk and 3265 ss_promo_sk = p_promo_sk and 3266 hd1.hd_income_band_sk = ib1.ib_income_band_sk and 3267 hd2.hd_income_band_sk = ib2.ib_income_band_sk and 3268 cd1.cd_marital_status <> cd2.cd_marital_status and 3269 i_color in ('orange','lace','lawn','misty','blush','pink') and 3270 i_current_price between 48 and 48 + 10 and 3271 i_current_price between 48 + 1 and 48 + 15 3272 group by i_product_name 3273 ,i_item_sk 3274 ,s_store_name 3275 ,s_zip 3276 ,ad1.ca_street_number 3277 ,ad1.ca_street_name 3278 ,ad1.ca_city 3279 ,ad1.ca_zip 3280 ,ad2.ca_street_number 3281 ,ad2.ca_street_name 3282 ,ad2.ca_city 3283 ,ad2.ca_zip 3284 ,d1.d_year 3285 ,d2.d_year 3286 ,d3.d_year 3287 ) 3288 select cs1.product_name 3289 ,cs1.store_name 3290 ,cs1.store_zip 3291 ,cs1.b_street_number 3292 ,cs1.b_street_name 3293 ,cs1.b_city 3294 ,cs1.b_zip 3295 ,cs1.c_street_number 3296 ,cs1.c_street_name 3297 ,cs1.c_city 3298 ,cs1.c_zip 3299 ,cs1.syear 3300 ,cs1.cnt 3301 ,cs1.s1 as s11 3302 ,cs1.s2 as s21 3303 ,cs1.s3 as s31 3304 ,cs2.s1 as s12 3305 ,cs2.s2 as s22 3306 ,cs2.s3 as s32 3307 ,cs2.syear 3308 ,cs2.cnt 3309 from cross_sales cs1,cross_sales cs2 3310 where cs1.item_sk=cs2.item_sk and 3311 cs1.syear = 1999 and 3312 cs2.syear = 1999 + 1 and 3313 cs2.cnt <= cs1.cnt and 3314 cs1.store_name = cs2.store_name and 3315 cs1.store_zip = cs2.store_zip 3316 order by cs1.product_name 3317 ,cs1.store_name 3318 ,cs2.cnt 3319 ,cs1.s1 3320 ,cs2.s1;`, 3321 }, 3322 { 3323 Query: ` 3324 -- start query 65 in stream 0 using template query65.tpl 3325 select 3326 s_store_name, 3327 i_item_desc, 3328 sc.revenue, 3329 i_current_price, 3330 i_wholesale_cost, 3331 i_brand 3332 from store, item, 3333 (select ss_store_sk, avg(revenue) as ave 3334 from 3335 (select ss_store_sk, ss_item_sk, 3336 sum(ss_sales_price) as revenue 3337 from store_sales, date_dim 3338 where ss_sold_date_sk = d_date_sk and d_month_seq between 1176 and 1176+11 3339 group by ss_store_sk, ss_item_sk) sa 3340 group by ss_store_sk) sb, 3341 (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue 3342 from store_sales, date_dim 3343 where ss_sold_date_sk = d_date_sk and d_month_seq between 1176 and 1176+11 3344 group by ss_store_sk, ss_item_sk) sc 3345 where sb.ss_store_sk = sc.ss_store_sk and 3346 sc.revenue <= 0.1 * sb.ave and 3347 s_store_sk = sc.ss_store_sk and 3348 i_item_sk = sc.ss_item_sk 3349 order by s_store_name, i_item_desc 3350 limit 100;`, 3351 }, 3352 { 3353 Query: ` 3354 -- start query 66 in stream 0 using template query66.tpl 3355 select 3356 w_warehouse_name 3357 ,w_warehouse_sq_ft 3358 ,w_city 3359 ,w_county 3360 ,w_state 3361 ,w_country 3362 ,ship_carriers 3363 ,year 3364 ,sum(jan_sales) as jan_sales 3365 ,sum(feb_sales) as feb_sales 3366 ,sum(mar_sales) as mar_sales 3367 ,sum(apr_sales) as apr_sales 3368 ,sum(may_sales) as may_sales 3369 ,sum(jun_sales) as jun_sales 3370 ,sum(jul_sales) as jul_sales 3371 ,sum(aug_sales) as aug_sales 3372 ,sum(sep_sales) as sep_sales 3373 ,sum(oct_sales) as oct_sales 3374 ,sum(nov_sales) as nov_sales 3375 ,sum(dec_sales) as dec_sales 3376 ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot 3377 ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot 3378 ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot 3379 ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot 3380 ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot 3381 ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot 3382 ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot 3383 ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot 3384 ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot 3385 ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot 3386 ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot 3387 ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot 3388 ,sum(jan_net) as jan_net 3389 ,sum(feb_net) as feb_net 3390 ,sum(mar_net) as mar_net 3391 ,sum(apr_net) as apr_net 3392 ,sum(may_net) as may_net 3393 ,sum(jun_net) as jun_net 3394 ,sum(jul_net) as jul_net 3395 ,sum(aug_net) as aug_net 3396 ,sum(sep_net) as sep_net 3397 ,sum(oct_net) as oct_net 3398 ,sum(nov_net) as nov_net 3399 ,sum(dec_net) as dec_net 3400 from ( 3401 select 3402 w_warehouse_name 3403 ,w_warehouse_sq_ft 3404 ,w_city 3405 ,w_county 3406 ,w_state 3407 ,w_country 3408 ,'ORIENTAL' || ',' || 'BOXBUNDLES' as ship_carriers 3409 ,d_year as year 3410 ,sum(case when d_moy = 1 3411 then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales 3412 ,sum(case when d_moy = 2 3413 then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales 3414 ,sum(case when d_moy = 3 3415 then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales 3416 ,sum(case when d_moy = 4 3417 then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales 3418 ,sum(case when d_moy = 5 3419 then ws_ext_sales_price* ws_quantity else 0 end) as may_sales 3420 ,sum(case when d_moy = 6 3421 then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales 3422 ,sum(case when d_moy = 7 3423 then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales 3424 ,sum(case when d_moy = 8 3425 then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales 3426 ,sum(case when d_moy = 9 3427 then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales 3428 ,sum(case when d_moy = 10 3429 then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales 3430 ,sum(case when d_moy = 11 3431 then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales 3432 ,sum(case when d_moy = 12 3433 then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales 3434 ,sum(case when d_moy = 1 3435 then ws_net_paid_inc_ship * ws_quantity else 0 end) as jan_net 3436 ,sum(case when d_moy = 2 3437 then ws_net_paid_inc_ship * ws_quantity else 0 end) as feb_net 3438 ,sum(case when d_moy = 3 3439 then ws_net_paid_inc_ship * ws_quantity else 0 end) as mar_net 3440 ,sum(case when d_moy = 4 3441 then ws_net_paid_inc_ship * ws_quantity else 0 end) as apr_net 3442 ,sum(case when d_moy = 5 3443 then ws_net_paid_inc_ship * ws_quantity else 0 end) as may_net 3444 ,sum(case when d_moy = 6 3445 then ws_net_paid_inc_ship * ws_quantity else 0 end) as jun_net 3446 ,sum(case when d_moy = 7 3447 then ws_net_paid_inc_ship * ws_quantity else 0 end) as jul_net 3448 ,sum(case when d_moy = 8 3449 then ws_net_paid_inc_ship * ws_quantity else 0 end) as aug_net 3450 ,sum(case when d_moy = 9 3451 then ws_net_paid_inc_ship * ws_quantity else 0 end) as sep_net 3452 ,sum(case when d_moy = 10 3453 then ws_net_paid_inc_ship * ws_quantity else 0 end) as oct_net 3454 ,sum(case when d_moy = 11 3455 then ws_net_paid_inc_ship * ws_quantity else 0 end) as nov_net 3456 ,sum(case when d_moy = 12 3457 then ws_net_paid_inc_ship * ws_quantity else 0 end) as dec_net 3458 from 3459 web_sales 3460 ,warehouse 3461 ,date_dim 3462 ,time_dim 3463 ,ship_mode 3464 where 3465 ws_warehouse_sk = w_warehouse_sk 3466 and ws_sold_date_sk = d_date_sk 3467 and ws_sold_time_sk = t_time_sk 3468 and ws_ship_mode_sk = sm_ship_mode_sk 3469 and d_year = 2001 3470 and t_time between 42970 and 42970+28800 3471 and sm_carrier in ('ORIENTAL','BOXBUNDLES') 3472 group by 3473 w_warehouse_name 3474 ,w_warehouse_sq_ft 3475 ,w_city 3476 ,w_county 3477 ,w_state 3478 ,w_country 3479 ,d_year 3480 union all 3481 select 3482 w_warehouse_name 3483 ,w_warehouse_sq_ft 3484 ,w_city 3485 ,w_county 3486 ,w_state 3487 ,w_country 3488 ,'ORIENTAL' || ',' || 'BOXBUNDLES' as ship_carriers 3489 ,d_year as year 3490 ,sum(case when d_moy = 1 3491 then cs_ext_list_price* cs_quantity else 0 end) as jan_sales 3492 ,sum(case when d_moy = 2 3493 then cs_ext_list_price* cs_quantity else 0 end) as feb_sales 3494 ,sum(case when d_moy = 3 3495 then cs_ext_list_price* cs_quantity else 0 end) as mar_sales 3496 ,sum(case when d_moy = 4 3497 then cs_ext_list_price* cs_quantity else 0 end) as apr_sales 3498 ,sum(case when d_moy = 5 3499 then cs_ext_list_price* cs_quantity else 0 end) as may_sales 3500 ,sum(case when d_moy = 6 3501 then cs_ext_list_price* cs_quantity else 0 end) as jun_sales 3502 ,sum(case when d_moy = 7 3503 then cs_ext_list_price* cs_quantity else 0 end) as jul_sales 3504 ,sum(case when d_moy = 8 3505 then cs_ext_list_price* cs_quantity else 0 end) as aug_sales 3506 ,sum(case when d_moy = 9 3507 then cs_ext_list_price* cs_quantity else 0 end) as sep_sales 3508 ,sum(case when d_moy = 10 3509 then cs_ext_list_price* cs_quantity else 0 end) as oct_sales 3510 ,sum(case when d_moy = 11 3511 then cs_ext_list_price* cs_quantity else 0 end) as nov_sales 3512 ,sum(case when d_moy = 12 3513 then cs_ext_list_price* cs_quantity else 0 end) as dec_sales 3514 ,sum(case when d_moy = 1 3515 then cs_net_paid * cs_quantity else 0 end) as jan_net 3516 ,sum(case when d_moy = 2 3517 then cs_net_paid * cs_quantity else 0 end) as feb_net 3518 ,sum(case when d_moy = 3 3519 then cs_net_paid * cs_quantity else 0 end) as mar_net 3520 ,sum(case when d_moy = 4 3521 then cs_net_paid * cs_quantity else 0 end) as apr_net 3522 ,sum(case when d_moy = 5 3523 then cs_net_paid * cs_quantity else 0 end) as may_net 3524 ,sum(case when d_moy = 6 3525 then cs_net_paid * cs_quantity else 0 end) as jun_net 3526 ,sum(case when d_moy = 7 3527 then cs_net_paid * cs_quantity else 0 end) as jul_net 3528 ,sum(case when d_moy = 8 3529 then cs_net_paid * cs_quantity else 0 end) as aug_net 3530 ,sum(case when d_moy = 9 3531 then cs_net_paid * cs_quantity else 0 end) as sep_net 3532 ,sum(case when d_moy = 10 3533 then cs_net_paid * cs_quantity else 0 end) as oct_net 3534 ,sum(case when d_moy = 11 3535 then cs_net_paid * cs_quantity else 0 end) as nov_net 3536 ,sum(case when d_moy = 12 3537 then cs_net_paid * cs_quantity else 0 end) as dec_net 3538 from 3539 catalog_sales 3540 ,warehouse 3541 ,date_dim 3542 ,time_dim 3543 ,ship_mode 3544 where 3545 cs_warehouse_sk = w_warehouse_sk 3546 and cs_sold_date_sk = d_date_sk 3547 and cs_sold_time_sk = t_time_sk 3548 and cs_ship_mode_sk = sm_ship_mode_sk 3549 and d_year = 2001 3550 and t_time between 42970 AND 42970+28800 3551 and sm_carrier in ('ORIENTAL','BOXBUNDLES') 3552 group by 3553 w_warehouse_name 3554 ,w_warehouse_sq_ft 3555 ,w_city 3556 ,w_county 3557 ,w_state 3558 ,w_country 3559 ,d_year 3560 ) x 3561 group by 3562 w_warehouse_name 3563 ,w_warehouse_sq_ft 3564 ,w_city 3565 ,w_county 3566 ,w_state 3567 ,w_country 3568 ,ship_carriers 3569 ,year 3570 order by w_warehouse_name 3571 limit 100;`, 3572 }, 3573 { 3574 Query: ` 3575 -- start query 67 in stream 0 using template query67.tpl 3576 select * 3577 from (select i_category 3578 ,i_class 3579 ,i_brand 3580 ,i_product_name 3581 ,d_year 3582 ,d_qoy 3583 ,d_moy 3584 ,s_store_id 3585 ,sumsales 3586 ,rank() over (partition by i_category order by sumsales desc) rk 3587 from (select i_category 3588 ,i_class 3589 ,i_brand 3590 ,i_product_name 3591 ,d_year 3592 ,d_qoy 3593 ,d_moy 3594 ,s_store_id 3595 ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales 3596 from store_sales 3597 ,date_dim 3598 ,store 3599 ,item 3600 where ss_sold_date_sk=d_date_sk 3601 and ss_item_sk=i_item_sk 3602 and ss_store_sk = s_store_sk 3603 and d_month_seq between 1217 and 1217+11 3604 group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2 3605 where rk <= 100 3606 order by i_category 3607 ,i_class 3608 ,i_brand 3609 ,i_product_name 3610 ,d_year 3611 ,d_qoy 3612 ,d_moy 3613 ,s_store_id 3614 ,sumsales 3615 ,rk 3616 limit 100;`, 3617 Skip: true, 3618 }, 3619 { 3620 Query: ` 3621 -- start query 68 in stream 0 using template query68.tpl 3622 select c_last_name 3623 ,c_first_name 3624 ,ca_city 3625 ,bought_city 3626 ,ss_ticket_number 3627 ,extended_price 3628 ,extended_tax 3629 ,list_price 3630 from (select ss_ticket_number 3631 ,ss_customer_sk 3632 ,ca_city bought_city 3633 ,sum(ss_ext_sales_price) extended_price 3634 ,sum(ss_ext_list_price) list_price 3635 ,sum(ss_ext_tax) extended_tax 3636 from store_sales 3637 ,date_dim 3638 ,store 3639 ,household_demographics 3640 ,customer_address 3641 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 3642 and store_sales.ss_store_sk = store.s_store_sk 3643 and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk 3644 and store_sales.ss_addr_sk = customer_address.ca_address_sk 3645 and date_dim.d_dom between 1 and 2 3646 and (household_demographics.hd_dep_count = 3 or 3647 household_demographics.hd_vehicle_count= 4) 3648 and date_dim.d_year in (1998,1998+1,1998+2) 3649 and store.s_city in ('Fairview','Midway') 3650 group by ss_ticket_number 3651 ,ss_customer_sk 3652 ,ss_addr_sk,ca_city) dn 3653 ,customer 3654 ,customer_address current_addr 3655 where ss_customer_sk = c_customer_sk 3656 and customer.c_current_addr_sk = current_addr.ca_address_sk 3657 and current_addr.ca_city <> bought_city 3658 order by c_last_name 3659 ,ss_ticket_number 3660 limit 100;`, 3661 }, 3662 { 3663 Query: ` 3664 -- start query 69 in stream 0 using template query69.tpl 3665 select 3666 cd_gender, 3667 cd_marital_status, 3668 cd_education_status, 3669 count(*) cnt1, 3670 cd_purchase_estimate, 3671 count(*) cnt2, 3672 cd_credit_rating, 3673 count(*) cnt3 3674 from 3675 customer c,customer_address ca,customer_demographics 3676 where 3677 c.c_current_addr_sk = ca.ca_address_sk and 3678 ca_state in ('IL','TX','ME') and 3679 cd_demo_sk = c.c_current_cdemo_sk and 3680 exists (select * 3681 from store_sales,date_dim 3682 where c.c_customer_sk = ss_customer_sk and 3683 ss_sold_date_sk = d_date_sk and 3684 d_year = 2002 and 3685 d_moy between 1 and 1+2) and 3686 (not exists (select * 3687 from web_sales,date_dim 3688 where c.c_customer_sk = ws_bill_customer_sk and 3689 ws_sold_date_sk = d_date_sk and 3690 d_year = 2002 and 3691 d_moy between 1 and 1+2) and 3692 not exists (select * 3693 from catalog_sales,date_dim 3694 where c.c_customer_sk = cs_ship_customer_sk and 3695 cs_sold_date_sk = d_date_sk and 3696 d_year = 2002 and 3697 d_moy between 1 and 1+2)) 3698 group by cd_gender, 3699 cd_marital_status, 3700 cd_education_status, 3701 cd_purchase_estimate, 3702 cd_credit_rating 3703 order by cd_gender, 3704 cd_marital_status, 3705 cd_education_status, 3706 cd_purchase_estimate, 3707 cd_credit_rating 3708 limit 100;`, 3709 }, 3710 { 3711 Query: ` 3712 -- start query 70 in stream 0 using template query70.tpl 3713 select 3714 sum(ss_net_profit) as total_sum 3715 ,s_state 3716 ,s_county 3717 ,grouping(s_state)+grouping(s_county) as lochierarchy 3718 ,rank() over ( 3719 partition by grouping(s_state)+grouping(s_county), 3720 case when grouping(s_county) = 0 then s_state end 3721 order by sum(ss_net_profit) desc) as rank_within_parent 3722 from 3723 store_sales 3724 ,date_dim d1 3725 ,store 3726 where 3727 d1.d_month_seq between 1220 and 1220+11 3728 and d1.d_date_sk = ss_sold_date_sk 3729 and s_store_sk = ss_store_sk 3730 and s_state in 3731 ( select s_state 3732 from (select s_state as s_state, 3733 rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking 3734 from store_sales, store, date_dim 3735 where d_month_seq between 1220 and 1220+11 3736 and d_date_sk = ss_sold_date_sk 3737 and s_store_sk = ss_store_sk 3738 group by s_state 3739 ) tmp1 3740 where ranking <= 5 3741 ) 3742 group by rollup(s_state,s_county) 3743 order by 3744 lochierarchy desc 3745 ,case when lochierarchy = 0 then s_state end 3746 ,rank_within_parent 3747 limit 100;`, 3748 Skip: true, 3749 }, 3750 { 3751 Query: ` 3752 -- start query 71 in stream 0 using template query71.tpl 3753 select i_brand_id brand_id, i_brand brand,t_hour,t_minute, 3754 sum(ext_price) ext_price 3755 from item, (select ws_ext_sales_price as ext_price, 3756 ws_sold_date_sk as sold_date_sk, 3757 ws_item_sk as sold_item_sk, 3758 ws_sold_time_sk as time_sk 3759 from web_sales,date_dim 3760 where d_date_sk = ws_sold_date_sk 3761 and d_moy=12 3762 and d_year=2002 3763 union all 3764 select cs_ext_sales_price as ext_price, 3765 cs_sold_date_sk as sold_date_sk, 3766 cs_item_sk as sold_item_sk, 3767 cs_sold_time_sk as time_sk 3768 from catalog_sales,date_dim 3769 where d_date_sk = cs_sold_date_sk 3770 and d_moy=12 3771 and d_year=2002 3772 union all 3773 select ss_ext_sales_price as ext_price, 3774 ss_sold_date_sk as sold_date_sk, 3775 ss_item_sk as sold_item_sk, 3776 ss_sold_time_sk as time_sk 3777 from store_sales,date_dim 3778 where d_date_sk = ss_sold_date_sk 3779 and d_moy=12 3780 and d_year=2002 3781 ) tmp,time_dim 3782 where 3783 sold_item_sk = i_item_sk 3784 and i_manager_id=1 3785 and time_sk = t_time_sk 3786 and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') 3787 group by i_brand, i_brand_id,t_hour,t_minute 3788 order by ext_price desc, i_brand_id 3789 ;`, 3790 }, 3791 { 3792 Query: ` 3793 -- start query 72 in stream 0 using template query72.tpl 3794 select i_item_desc 3795 ,w_warehouse_name 3796 ,d1.d_week_seq 3797 ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo 3798 ,sum(case when p_promo_sk is not null then 1 else 0 end) promo 3799 ,count(*) total_cnt 3800 from catalog_sales 3801 join inventory on (cs_item_sk = inv_item_sk) 3802 join warehouse on (w_warehouse_sk=inv_warehouse_sk) 3803 join item on (i_item_sk = cs_item_sk) 3804 join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) 3805 join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) 3806 join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) 3807 join date_dim d2 on (inv_date_sk = d2.d_date_sk) 3808 join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) 3809 left outer join promotion on (cs_promo_sk=p_promo_sk) 3810 left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) 3811 where d1.d_week_seq = d2.d_week_seq 3812 and inv_quantity_on_hand < cs_quantity 3813 and d3.d_date > d1.d_date + 5 3814 and hd_buy_potential = '1001-5000' 3815 and d1.d_year = 1998 3816 and cd_marital_status = 'S' 3817 group by i_item_desc,w_warehouse_name,d1.d_week_seq 3818 order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq 3819 limit 100;`, 3820 }, 3821 { 3822 Query: ` 3823 -- start query 73 in stream 0 using template query73.tpl 3824 select c_last_name 3825 ,c_first_name 3826 ,c_salutation 3827 ,c_preferred_cust_flag 3828 ,ss_ticket_number 3829 ,cnt from 3830 (select ss_ticket_number 3831 ,ss_customer_sk 3832 ,count(*) cnt 3833 from store_sales,date_dim,store,household_demographics 3834 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 3835 and store_sales.ss_store_sk = store.s_store_sk 3836 and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk 3837 and date_dim.d_dom between 1 and 2 3838 and (household_demographics.hd_buy_potential = '1001-5000' or 3839 household_demographics.hd_buy_potential = '5001-10000') 3840 and household_demographics.hd_vehicle_count > 0 3841 and case when household_demographics.hd_vehicle_count > 0 then 3842 household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 3843 and date_dim.d_year in (2000,2000+1,2000+2) 3844 and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County') 3845 group by ss_ticket_number,ss_customer_sk) dj,customer 3846 where ss_customer_sk = c_customer_sk 3847 and cnt between 1 and 5 3848 order by cnt desc, c_last_name asc;`, 3849 }, 3850 { 3851 Query: ` 3852 -- start query 74 in stream 0 using template query74.tpl 3853 with year_total as ( 3854 select c_customer_id customer_id 3855 ,c_first_name customer_first_name 3856 ,c_last_name customer_last_name 3857 ,d_year as year 3858 ,max(ss_net_paid) year_total 3859 ,'s' sale_type 3860 from customer 3861 ,store_sales 3862 ,date_dim 3863 where c_customer_sk = ss_customer_sk 3864 and ss_sold_date_sk = d_date_sk 3865 and d_year in (1999,1999+1) 3866 group by c_customer_id 3867 ,c_first_name 3868 ,c_last_name 3869 ,d_year 3870 union all 3871 select c_customer_id customer_id 3872 ,c_first_name customer_first_name 3873 ,c_last_name customer_last_name 3874 ,d_year as year 3875 ,max(ws_net_paid) year_total 3876 ,'w' sale_type 3877 from customer 3878 ,web_sales 3879 ,date_dim 3880 where c_customer_sk = ws_bill_customer_sk 3881 and ws_sold_date_sk = d_date_sk 3882 and d_year in (1999,1999+1) 3883 group by c_customer_id 3884 ,c_first_name 3885 ,c_last_name 3886 ,d_year 3887 ) 3888 select 3889 t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name 3890 from year_total t_s_firstyear 3891 ,year_total t_s_secyear 3892 ,year_total t_w_firstyear 3893 ,year_total t_w_secyear 3894 where t_s_secyear.customer_id = t_s_firstyear.customer_id 3895 and t_s_firstyear.customer_id = t_w_secyear.customer_id 3896 and t_s_firstyear.customer_id = t_w_firstyear.customer_id 3897 and t_s_firstyear.sale_type = 's' 3898 and t_w_firstyear.sale_type = 'w' 3899 and t_s_secyear.sale_type = 's' 3900 and t_w_secyear.sale_type = 'w' 3901 and t_s_firstyear.year = 1999 3902 and t_s_secyear.year = 1999+1 3903 and t_w_firstyear.year = 1999 3904 and t_w_secyear.year = 1999+1 3905 and t_s_firstyear.year_total > 0 3906 and t_w_firstyear.year_total > 0 3907 and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end 3908 > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end 3909 order by 1,3,2 3910 limit 100;`, 3911 }, 3912 { 3913 Query: ` 3914 -- start query 75 in stream 0 using template query75.tpl 3915 WITH all_sales AS ( 3916 SELECT d_year 3917 ,i_brand_id 3918 ,i_class_id 3919 ,i_category_id 3920 ,i_manufact_id 3921 ,SUM(sales_cnt) AS sales_cnt 3922 ,SUM(sales_amt) AS sales_amt 3923 FROM (SELECT d_year 3924 ,i_brand_id 3925 ,i_class_id 3926 ,i_category_id 3927 ,i_manufact_id 3928 ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt 3929 ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt 3930 FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk 3931 JOIN date_dim ON d_date_sk=cs_sold_date_sk 3932 LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number 3933 AND cs_item_sk=cr_item_sk) 3934 WHERE i_category='Sports' 3935 UNION 3936 SELECT d_year 3937 ,i_brand_id 3938 ,i_class_id 3939 ,i_category_id 3940 ,i_manufact_id 3941 ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt 3942 ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt 3943 FROM store_sales JOIN item ON i_item_sk=ss_item_sk 3944 JOIN date_dim ON d_date_sk=ss_sold_date_sk 3945 LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number 3946 AND ss_item_sk=sr_item_sk) 3947 WHERE i_category='Sports' 3948 UNION 3949 SELECT d_year 3950 ,i_brand_id 3951 ,i_class_id 3952 ,i_category_id 3953 ,i_manufact_id 3954 ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt 3955 ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt 3956 FROM web_sales JOIN item ON i_item_sk=ws_item_sk 3957 JOIN date_dim ON d_date_sk=ws_sold_date_sk 3958 LEFT JOIN web_returns ON (ws_order_number=wr_order_number 3959 AND ws_item_sk=wr_item_sk) 3960 WHERE i_category='Sports') sales_detail 3961 GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) 3962 SELECT prev_yr.d_year AS prev_year 3963 ,curr_yr.d_year AS year 3964 ,curr_yr.i_brand_id 3965 ,curr_yr.i_class_id 3966 ,curr_yr.i_category_id 3967 ,curr_yr.i_manufact_id 3968 ,prev_yr.sales_cnt AS prev_yr_cnt 3969 ,curr_yr.sales_cnt AS curr_yr_cnt 3970 ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff 3971 ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff 3972 FROM all_sales curr_yr, all_sales prev_yr 3973 WHERE curr_yr.i_brand_id=prev_yr.i_brand_id 3974 AND curr_yr.i_class_id=prev_yr.i_class_id 3975 AND curr_yr.i_category_id=prev_yr.i_category_id 3976 AND curr_yr.i_manufact_id=prev_yr.i_manufact_id 3977 AND curr_yr.d_year=2002 3978 AND prev_yr.d_year=2002-1 3979 AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 3980 ORDER BY sales_cnt_diff,sales_amt_diff 3981 limit 100;`, 3982 }, 3983 { 3984 Query: ` 3985 -- start query 76 in stream 0 using template query76.tpl 3986 select channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( 3987 SELECT 'store' as channel, 'ss_customer_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price 3988 FROM store_sales, item, date_dim 3989 WHERE ss_customer_sk IS NULL 3990 AND ss_sold_date_sk=d_date_sk 3991 AND ss_item_sk=i_item_sk 3992 UNION ALL 3993 SELECT 'web' as channel, 'ws_promo_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price 3994 FROM web_sales, item, date_dim 3995 WHERE ws_promo_sk IS NULL 3996 AND ws_sold_date_sk=d_date_sk 3997 AND ws_item_sk=i_item_sk 3998 UNION ALL 3999 SELECT 'catalog' as channel, 'cs_bill_customer_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price 4000 FROM catalog_sales, item, date_dim 4001 WHERE cs_bill_customer_sk IS NULL 4002 AND cs_sold_date_sk=d_date_sk 4003 AND cs_item_sk=i_item_sk) foo 4004 GROUP BY channel, col_name, d_year, d_qoy, i_category 4005 ORDER BY channel, col_name, d_year, d_qoy, i_category 4006 limit 100;`, 4007 }, 4008 { 4009 Query: ` 4010 -- start query 77 in stream 0 using template query77.tpl 4011 with ss as 4012 (select s_store_sk, 4013 sum(ss_ext_sales_price) as sales, 4014 sum(ss_net_profit) as profit 4015 from store_sales, 4016 date_dim, 4017 store 4018 where ss_sold_date_sk = d_date_sk 4019 and d_date between cast('2000-08-10' as date) 4020 and (cast('2000-08-10' as date) + interval 30 day) 4021 and ss_store_sk = s_store_sk 4022 group by s_store_sk) 4023 , 4024 sr as 4025 (select s_store_sk, 4026 sum(sr_return_amt) as returns, 4027 sum(sr_net_loss) as profit_loss 4028 from store_returns, 4029 date_dim, 4030 store 4031 where sr_returned_date_sk = d_date_sk 4032 and d_date between cast('2000-08-10' as date) 4033 and (cast('2000-08-10' as date) + interval 30 day) 4034 and sr_store_sk = s_store_sk 4035 group by s_store_sk), 4036 cs as 4037 (select cs_call_center_sk, 4038 sum(cs_ext_sales_price) as sales, 4039 sum(cs_net_profit) as profit 4040 from catalog_sales, 4041 date_dim 4042 where cs_sold_date_sk = d_date_sk 4043 and d_date between cast('2000-08-10' as date) 4044 and (cast('2000-08-10' as date) + interval 30 day) 4045 group by cs_call_center_sk 4046 ), 4047 cr as 4048 (select cr_call_center_sk, 4049 sum(cr_return_amount) as returns, 4050 sum(cr_net_loss) as profit_loss 4051 from catalog_returns, 4052 date_dim 4053 where cr_returned_date_sk = d_date_sk 4054 and d_date between cast('2000-08-10' as date) 4055 and (cast('2000-08-10' as date) + interval 30 day) 4056 group by cr_call_center_sk 4057 ), 4058 ws as 4059 ( select wp_web_page_sk, 4060 sum(ws_ext_sales_price) as sales, 4061 sum(ws_net_profit) as profit 4062 from web_sales, 4063 date_dim, 4064 web_page 4065 where ws_sold_date_sk = d_date_sk 4066 and d_date between cast('2000-08-10' as date) 4067 and (cast('2000-08-10' as date) + interval 30 day) 4068 and ws_web_page_sk = wp_web_page_sk 4069 group by wp_web_page_sk), 4070 wr as 4071 (select wp_web_page_sk, 4072 sum(wr_return_amt) as returns, 4073 sum(wr_net_loss) as profit_loss 4074 from web_returns, 4075 date_dim, 4076 web_page 4077 where wr_returned_date_sk = d_date_sk 4078 and d_date between cast('2000-08-10' as date) 4079 and (cast('2000-08-10' as date) + interval 30 day) 4080 and wr_web_page_sk = wp_web_page_sk 4081 group by wp_web_page_sk) 4082 select channel 4083 , id 4084 , sum(sales) as sales 4085 , sum(returns) as returns 4086 , sum(profit) as profit 4087 from 4088 (select 'store channel' as channel 4089 , ss.s_store_sk as id 4090 , sales 4091 , coalesce(returns, 0) as returns 4092 , (profit - coalesce(profit_loss,0)) as profit 4093 from ss left join sr 4094 on ss.s_store_sk = sr.s_store_sk 4095 union all 4096 select 'catalog channel' as channel 4097 , cs_call_center_sk as id 4098 , sales 4099 , returns 4100 , (profit - profit_loss) as profit 4101 from cs 4102 , cr 4103 union all 4104 select 'web channel' as channel 4105 , ws.wp_web_page_sk as id 4106 , sales 4107 , coalesce(returns, 0) returns 4108 , (profit - coalesce(profit_loss,0)) as profit 4109 from ws left join wr 4110 on ws.wp_web_page_sk = wr.wp_web_page_sk 4111 ) x 4112 group by rollup (channel, id) 4113 order by channel 4114 ,id 4115 limit 100;`, 4116 Skip: true, 4117 }, 4118 { 4119 Query: ` 4120 -- start query 78 in stream 0 using template query78.tpl 4121 with ws as 4122 (select d_year AS ws_sold_year, ws_item_sk, 4123 ws_bill_customer_sk ws_customer_sk, 4124 sum(ws_quantity) ws_qty, 4125 sum(ws_wholesale_cost) ws_wc, 4126 sum(ws_sales_price) ws_sp 4127 from web_sales 4128 left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk 4129 join date_dim on ws_sold_date_sk = d_date_sk 4130 where wr_order_number is null 4131 group by d_year, ws_item_sk, ws_bill_customer_sk 4132 ), 4133 cs as 4134 (select d_year AS cs_sold_year, cs_item_sk, 4135 cs_bill_customer_sk cs_customer_sk, 4136 sum(cs_quantity) cs_qty, 4137 sum(cs_wholesale_cost) cs_wc, 4138 sum(cs_sales_price) cs_sp 4139 from catalog_sales 4140 left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk 4141 join date_dim on cs_sold_date_sk = d_date_sk 4142 where cr_order_number is null 4143 group by d_year, cs_item_sk, cs_bill_customer_sk 4144 ), 4145 ss as 4146 (select d_year AS ss_sold_year, ss_item_sk, 4147 ss_customer_sk, 4148 sum(ss_quantity) ss_qty, 4149 sum(ss_wholesale_cost) ss_wc, 4150 sum(ss_sales_price) ss_sp 4151 from store_sales 4152 left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk 4153 join date_dim on ss_sold_date_sk = d_date_sk 4154 where sr_ticket_number is null 4155 group by d_year, ss_item_sk, ss_customer_sk 4156 ) 4157 select 4158 ss_customer_sk, 4159 round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, 4160 ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, 4161 coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, 4162 coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, 4163 coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price 4164 from ss 4165 left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) 4166 left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) 4167 where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=1998 4168 order by 4169 ss_customer_sk, 4170 ss_qty desc, ss_wc desc, ss_sp desc, 4171 other_chan_qty, 4172 other_chan_wholesale_cost, 4173 other_chan_sales_price, 4174 ratio 4175 limit 100;`, 4176 }, 4177 { 4178 Query: ` 4179 -- start query 79 in stream 0 using template query79.tpl 4180 select 4181 c_last_name,c_first_name,substr(s_city,1,30),ss_ticket_number,amt,profit 4182 from 4183 (select ss_ticket_number 4184 ,ss_customer_sk 4185 ,store.s_city 4186 ,sum(ss_coupon_amt) amt 4187 ,sum(ss_net_profit) profit 4188 from store_sales,date_dim,store,household_demographics 4189 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 4190 and store_sales.ss_store_sk = store.s_store_sk 4191 and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk 4192 and (household_demographics.hd_dep_count = 7 or household_demographics.hd_vehicle_count > -1) 4193 and date_dim.d_dow = 1 4194 and date_dim.d_year in (2000,2000+1,2000+2) 4195 and store.s_number_employees between 200 and 295 4196 group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer 4197 where ss_customer_sk = c_customer_sk 4198 order by c_last_name,c_first_name,substr(s_city,1,30), profit 4199 limit 100;`, 4200 }, 4201 { 4202 Query: ` 4203 -- start query 80 in stream 0 using template query80.tpl 4204 with ssr as 4205 (select s_store_id as store_id, 4206 sum(ss_ext_sales_price) as sales, 4207 sum(coalesce(sr_return_amt, 0)) as returns, 4208 sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit 4209 from store_sales left outer join store_returns on 4210 (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), 4211 date_dim, 4212 store, 4213 item, 4214 promotion 4215 where ss_sold_date_sk = d_date_sk 4216 and d_date between cast('2002-08-14' as date) 4217 and (cast('2002-08-14' as date) + interval 30 day) 4218 and ss_store_sk = s_store_sk 4219 and ss_item_sk = i_item_sk 4220 and i_current_price > 50 4221 and ss_promo_sk = p_promo_sk 4222 and p_channel_tv = 'N' 4223 group by s_store_id) 4224 , 4225 csr as 4226 (select cp_catalog_page_id as catalog_page_id, 4227 sum(cs_ext_sales_price) as sales, 4228 sum(coalesce(cr_return_amount, 0)) as returns, 4229 sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit 4230 from catalog_sales left outer join catalog_returns on 4231 (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), 4232 date_dim, 4233 catalog_page, 4234 item, 4235 promotion 4236 where cs_sold_date_sk = d_date_sk 4237 and d_date between cast('2002-08-14' as date) 4238 and (cast('2002-08-14' as date) + interval 30 day) 4239 and cs_catalog_page_sk = cp_catalog_page_sk 4240 and cs_item_sk = i_item_sk 4241 and i_current_price > 50 4242 and cs_promo_sk = p_promo_sk 4243 and p_channel_tv = 'N' 4244 group by cp_catalog_page_id) 4245 , 4246 wsr as 4247 (select web_site_id, 4248 sum(ws_ext_sales_price) as sales, 4249 sum(coalesce(wr_return_amt, 0)) as returns, 4250 sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit 4251 from web_sales left outer join web_returns on 4252 (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), 4253 date_dim, 4254 web_site, 4255 item, 4256 promotion 4257 where ws_sold_date_sk = d_date_sk 4258 and d_date between cast('2002-08-14' as date) 4259 and (cast('2002-08-14' as date) + interval 30 day) 4260 and ws_web_site_sk = web_site_sk 4261 and ws_item_sk = i_item_sk 4262 and i_current_price > 50 4263 and ws_promo_sk = p_promo_sk 4264 and p_channel_tv = 'N' 4265 group by web_site_id) 4266 select channel 4267 , id 4268 , sum(sales) as sales 4269 , sum(returns) as returns 4270 , sum(profit) as profit 4271 from 4272 (select 'store channel' as channel 4273 , 'store' || store_id as id 4274 , sales 4275 , returns 4276 , profit 4277 from ssr 4278 union all 4279 select 'catalog channel' as channel 4280 , 'catalog_page' || catalog_page_id as id 4281 , sales 4282 , returns 4283 , profit 4284 from csr 4285 union all 4286 select 'web channel' as channel 4287 , 'web_site' || web_site_id as id 4288 , sales 4289 , returns 4290 , profit 4291 from wsr 4292 ) x 4293 group by rollup (channel, id) 4294 order by channel 4295 ,id 4296 limit 100;`, 4297 Skip: true, 4298 }, 4299 { 4300 Query: ` 4301 -- start query 81 in stream 0 using template query81.tpl 4302 with customer_total_return as 4303 (select cr_returning_customer_sk as ctr_customer_sk 4304 ,ca_state as ctr_state, 4305 sum(cr_return_amt_inc_tax) as ctr_total_return 4306 from catalog_returns 4307 ,date_dim 4308 ,customer_address 4309 where cr_returned_date_sk = d_date_sk 4310 and d_year =2001 4311 and cr_returning_addr_sk = ca_address_sk 4312 group by cr_returning_customer_sk 4313 ,ca_state ) 4314 select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name 4315 ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset 4316 ,ca_location_type,ctr_total_return 4317 from customer_total_return ctr1 4318 ,customer_address 4319 ,customer 4320 where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 4321 from customer_total_return ctr2 4322 where ctr1.ctr_state = ctr2.ctr_state) 4323 and ca_address_sk = c_current_addr_sk 4324 and ca_state = 'TN' 4325 and ctr1.ctr_customer_sk = c_customer_sk 4326 order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name 4327 ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset 4328 ,ca_location_type,ctr_total_return 4329 limit 100;`, 4330 }, 4331 { 4332 Query: ` 4333 -- start query 82 in stream 0 using template query82.tpl 4334 select i_item_id 4335 ,i_item_desc 4336 ,i_current_price 4337 from item, inventory, date_dim, store_sales 4338 where i_current_price between 58 and 58+30 4339 and inv_item_sk = i_item_sk 4340 and d_date_sk=inv_date_sk 4341 and d_date between cast('2001-01-13' as date) and (cast('2001-01-13' as date) + interval 60 day) 4342 and i_manufact_id in (259,559,580,485) 4343 and inv_quantity_on_hand between 100 and 500 4344 and ss_item_sk = i_item_sk 4345 group by i_item_id,i_item_desc,i_current_price 4346 order by i_item_id 4347 limit 100;`, 4348 }, 4349 { 4350 Query: ` 4351 -- start query 83 in stream 0 using template query83.tpl 4352 with sr_items as 4353 (select i_item_id item_id, 4354 sum(sr_return_quantity) sr_item_qty 4355 from store_returns, 4356 item, 4357 date_dim 4358 where sr_item_sk = i_item_sk 4359 and d_date in 4360 (select d_date 4361 from date_dim 4362 where d_week_seq in 4363 (select d_week_seq 4364 from date_dim 4365 where d_date in ('2001-07-13','2001-09-10','2001-11-16'))) 4366 and sr_returned_date_sk = d_date_sk 4367 group by i_item_id), 4368 cr_items as 4369 (select i_item_id item_id, 4370 sum(cr_return_quantity) cr_item_qty 4371 from catalog_returns, 4372 item, 4373 date_dim 4374 where cr_item_sk = i_item_sk 4375 and d_date in 4376 (select d_date 4377 from date_dim 4378 where d_week_seq in 4379 (select d_week_seq 4380 from date_dim 4381 where d_date in ('2001-07-13','2001-09-10','2001-11-16'))) 4382 and cr_returned_date_sk = d_date_sk 4383 group by i_item_id), 4384 wr_items as 4385 (select i_item_id item_id, 4386 sum(wr_return_quantity) wr_item_qty 4387 from web_returns, 4388 item, 4389 date_dim 4390 where wr_item_sk = i_item_sk 4391 and d_date in 4392 (select d_date 4393 from date_dim 4394 where d_week_seq in 4395 (select d_week_seq 4396 from date_dim 4397 where d_date in ('2001-07-13','2001-09-10','2001-11-16'))) 4398 and wr_returned_date_sk = d_date_sk 4399 group by i_item_id) 4400 select sr_items.item_id 4401 ,sr_item_qty 4402 ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev 4403 ,cr_item_qty 4404 ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev 4405 ,wr_item_qty 4406 ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev 4407 ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average 4408 from sr_items 4409 ,cr_items 4410 ,wr_items 4411 where sr_items.item_id=cr_items.item_id 4412 and sr_items.item_id=wr_items.item_id 4413 order by sr_items.item_id 4414 ,sr_item_qty 4415 limit 100;`, 4416 }, 4417 { 4418 Query: ` 4419 -- start query 84 in stream 0 using template query84.tpl 4420 select c_customer_id as customer_id 4421 , coalesce(c_last_name,'') || ', ' || coalesce(c_first_name,'') as customername 4422 from customer 4423 ,customer_address 4424 ,customer_demographics 4425 ,household_demographics 4426 ,income_band 4427 ,store_returns 4428 where ca_city = 'Woodland' 4429 and c_current_addr_sk = ca_address_sk 4430 and ib_lower_bound >= 60306 4431 and ib_upper_bound <= 60306 + 50000 4432 and ib_income_band_sk = hd_income_band_sk 4433 and cd_demo_sk = c_current_cdemo_sk 4434 and hd_demo_sk = c_current_hdemo_sk 4435 and sr_cdemo_sk = cd_demo_sk 4436 order by c_customer_id 4437 limit 100;`, 4438 }, 4439 { 4440 Query: ` 4441 -- start query 85 in stream 0 using template query85.tpl 4442 select substr(r_reason_desc,1,20) 4443 ,avg(ws_quantity) 4444 ,avg(wr_refunded_cash) 4445 ,avg(wr_fee) 4446 from web_sales, web_returns, web_page, customer_demographics cd1, 4447 customer_demographics cd2, customer_address, date_dim, reason 4448 where ws_web_page_sk = wp_web_page_sk 4449 and ws_item_sk = wr_item_sk 4450 and ws_order_number = wr_order_number 4451 and ws_sold_date_sk = d_date_sk and d_year = 1998 4452 and cd1.cd_demo_sk = wr_refunded_cdemo_sk 4453 and cd2.cd_demo_sk = wr_returning_cdemo_sk 4454 and ca_address_sk = wr_refunded_addr_sk 4455 and r_reason_sk = wr_reason_sk 4456 and 4457 ( 4458 ( 4459 cd1.cd_marital_status = 'D' 4460 and 4461 cd1.cd_marital_status = cd2.cd_marital_status 4462 and 4463 cd1.cd_education_status = 'Primary' 4464 and 4465 cd1.cd_education_status = cd2.cd_education_status 4466 and 4467 ws_sales_price between 100.00 and 150.00 4468 ) 4469 or 4470 ( 4471 cd1.cd_marital_status = 'S' 4472 and 4473 cd1.cd_marital_status = cd2.cd_marital_status 4474 and 4475 cd1.cd_education_status = 'College' 4476 and 4477 cd1.cd_education_status = cd2.cd_education_status 4478 and 4479 ws_sales_price between 50.00 and 100.00 4480 ) 4481 or 4482 ( 4483 cd1.cd_marital_status = 'U' 4484 and 4485 cd1.cd_marital_status = cd2.cd_marital_status 4486 and 4487 cd1.cd_education_status = 'Advanced Degree' 4488 and 4489 cd1.cd_education_status = cd2.cd_education_status 4490 and 4491 ws_sales_price between 150.00 and 200.00 4492 ) 4493 ) 4494 and 4495 ( 4496 ( 4497 ca_country = 'United States' 4498 and 4499 ca_state in ('NC', 'TX', 'IA') 4500 and ws_net_profit between 100 and 200 4501 ) 4502 or 4503 ( 4504 ca_country = 'United States' 4505 and 4506 ca_state in ('WI', 'WV', 'GA') 4507 and ws_net_profit between 150 and 300 4508 ) 4509 or 4510 ( 4511 ca_country = 'United States' 4512 and 4513 ca_state in ('OK', 'VA', 'KY') 4514 and ws_net_profit between 50 and 250 4515 ) 4516 ) 4517 group by r_reason_desc 4518 order by substr(r_reason_desc,1,20) 4519 ,avg(ws_quantity) 4520 ,avg(wr_refunded_cash) 4521 ,avg(wr_fee) 4522 limit 100;`, 4523 }, 4524 { 4525 Query: ` 4526 -- start query 86 in stream 0 using template query86.tpl 4527 select 4528 sum(ws_net_paid) as total_sum 4529 ,i_category 4530 ,i_class 4531 ,grouping(i_category)+grouping(i_class) as lochierarchy 4532 ,rank() over ( 4533 partition by grouping(i_category)+grouping(i_class), 4534 case when grouping(i_class) = 0 then i_category end 4535 order by sum(ws_net_paid) desc) as rank_within_parent 4536 from 4537 web_sales 4538 ,date_dim d1 4539 ,item 4540 where 4541 d1.d_month_seq between 1186 and 1186+11 4542 and d1.d_date_sk = ws_sold_date_sk 4543 and i_item_sk = ws_item_sk 4544 group by rollup(i_category,i_class) 4545 order by 4546 lochierarchy desc, 4547 case when lochierarchy = 0 then i_category end, 4548 rank_within_parent 4549 limit 100;`, 4550 Skip: true, 4551 }, 4552 { 4553 Query: ` 4554 -- start query 87 in stream 0 using template query87.tpl 4555 select count(*) 4556 from ((select distinct c_last_name, c_first_name, d_date 4557 from store_sales, date_dim, customer 4558 where store_sales.ss_sold_date_sk = date_dim.d_date_sk 4559 and store_sales.ss_customer_sk = customer.c_customer_sk 4560 and d_month_seq between 1202 and 1202+11) 4561 except 4562 (select distinct c_last_name, c_first_name, d_date 4563 from catalog_sales, date_dim, customer 4564 where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk 4565 and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk 4566 and d_month_seq between 1202 and 1202+11) 4567 except 4568 (select distinct c_last_name, c_first_name, d_date 4569 from web_sales, date_dim, customer 4570 where web_sales.ws_sold_date_sk = date_dim.d_date_sk 4571 and web_sales.ws_bill_customer_sk = customer.c_customer_sk 4572 and d_month_seq between 1202 and 1202+11) 4573 ) cool_cust 4574 ;`, 4575 }, 4576 { 4577 Query: ` 4578 -- start query 88 in stream 0 using template query88.tpl 4579 select * 4580 from 4581 (select count(*) h8_30_to_9 4582 from store_sales, household_demographics , time_dim, store 4583 where ss_sold_time_sk = time_dim.t_time_sk 4584 and ss_hdemo_sk = household_demographics.hd_demo_sk 4585 and ss_store_sk = s_store_sk 4586 and time_dim.t_hour = 8 4587 and time_dim.t_minute >= 30 4588 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4589 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4590 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4591 and store.s_store_name = 'ese') s1, 4592 (select count(*) h9_to_9_30 4593 from store_sales, household_demographics , time_dim, store 4594 where ss_sold_time_sk = time_dim.t_time_sk 4595 and ss_hdemo_sk = household_demographics.hd_demo_sk 4596 and ss_store_sk = s_store_sk 4597 and time_dim.t_hour = 9 4598 and time_dim.t_minute < 30 4599 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4600 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4601 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4602 and store.s_store_name = 'ese') s2, 4603 (select count(*) h9_30_to_10 4604 from store_sales, household_demographics , time_dim, store 4605 where ss_sold_time_sk = time_dim.t_time_sk 4606 and ss_hdemo_sk = household_demographics.hd_demo_sk 4607 and ss_store_sk = s_store_sk 4608 and time_dim.t_hour = 9 4609 and time_dim.t_minute >= 30 4610 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4611 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4612 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4613 and store.s_store_name = 'ese') s3, 4614 (select count(*) h10_to_10_30 4615 from store_sales, household_demographics , time_dim, store 4616 where ss_sold_time_sk = time_dim.t_time_sk 4617 and ss_hdemo_sk = household_demographics.hd_demo_sk 4618 and ss_store_sk = s_store_sk 4619 and time_dim.t_hour = 10 4620 and time_dim.t_minute < 30 4621 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4622 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4623 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4624 and store.s_store_name = 'ese') s4, 4625 (select count(*) h10_30_to_11 4626 from store_sales, household_demographics , time_dim, store 4627 where ss_sold_time_sk = time_dim.t_time_sk 4628 and ss_hdemo_sk = household_demographics.hd_demo_sk 4629 and ss_store_sk = s_store_sk 4630 and time_dim.t_hour = 10 4631 and time_dim.t_minute >= 30 4632 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4633 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4634 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4635 and store.s_store_name = 'ese') s5, 4636 (select count(*) h11_to_11_30 4637 from store_sales, household_demographics , time_dim, store 4638 where ss_sold_time_sk = time_dim.t_time_sk 4639 and ss_hdemo_sk = household_demographics.hd_demo_sk 4640 and ss_store_sk = s_store_sk 4641 and time_dim.t_hour = 11 4642 and time_dim.t_minute < 30 4643 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4644 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4645 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4646 and store.s_store_name = 'ese') s6, 4647 (select count(*) h11_30_to_12 4648 from store_sales, household_demographics , time_dim, store 4649 where ss_sold_time_sk = time_dim.t_time_sk 4650 and ss_hdemo_sk = household_demographics.hd_demo_sk 4651 and ss_store_sk = s_store_sk 4652 and time_dim.t_hour = 11 4653 and time_dim.t_minute >= 30 4654 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4655 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4656 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4657 and store.s_store_name = 'ese') s7, 4658 (select count(*) h12_to_12_30 4659 from store_sales, household_demographics , time_dim, store 4660 where ss_sold_time_sk = time_dim.t_time_sk 4661 and ss_hdemo_sk = household_demographics.hd_demo_sk 4662 and ss_store_sk = s_store_sk 4663 and time_dim.t_hour = 12 4664 and time_dim.t_minute < 30 4665 and ((household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2) or 4666 (household_demographics.hd_dep_count = -1 and household_demographics.hd_vehicle_count<=-1+2) or 4667 (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) 4668 and store.s_store_name = 'ese') s8 4669 ;`, 4670 }, 4671 { 4672 Query: ` 4673 -- start query 89 in stream 0 using template query89.tpl 4674 select * 4675 from( 4676 select i_category, i_class, i_brand, 4677 s_store_name, s_company_name, 4678 d_moy, 4679 sum(ss_sales_price) sum_sales, 4680 avg(sum(ss_sales_price)) over 4681 (partition by i_category, i_brand, s_store_name, s_company_name) 4682 avg_monthly_sales 4683 from item, store_sales, date_dim, store 4684 where ss_item_sk = i_item_sk and 4685 ss_sold_date_sk = d_date_sk and 4686 ss_store_sk = s_store_sk and 4687 d_year in (2001) and 4688 ((i_category in ('Books','Children','Electronics') and 4689 i_class in ('history','school-uniforms','audio') 4690 ) 4691 or (i_category in ('Men','Sports','Shoes') and 4692 i_class in ('pants','tennis','womens') 4693 )) 4694 group by i_category, i_class, i_brand, 4695 s_store_name, s_company_name, d_moy) tmp1 4696 where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 4697 order by sum_sales - avg_monthly_sales, s_store_name 4698 limit 100;`, 4699 }, 4700 { 4701 Query: ` 4702 -- start query 90 in stream 0 using template query90.tpl 4703 select cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio 4704 from ( select count(*) amc 4705 from web_sales, household_demographics , time_dim, web_page 4706 where ws_sold_time_sk = time_dim.t_time_sk 4707 and ws_ship_hdemo_sk = household_demographics.hd_demo_sk 4708 and ws_web_page_sk = web_page.wp_web_page_sk 4709 and time_dim.t_hour between 12 and 12+1 4710 and household_demographics.hd_dep_count = 6 4711 and web_page.wp_char_count between 5000 and 5200) at, 4712 ( select count(*) pmc 4713 from web_sales, household_demographics , time_dim, web_page 4714 where ws_sold_time_sk = time_dim.t_time_sk 4715 and ws_ship_hdemo_sk = household_demographics.hd_demo_sk 4716 and ws_web_page_sk = web_page.wp_web_page_sk 4717 and time_dim.t_hour between 14 and 14+1 4718 and household_demographics.hd_dep_count = 6 4719 and web_page.wp_char_count between 5000 and 5200) pt 4720 order by am_pm_ratio 4721 limit 100;`, 4722 }, 4723 { 4724 Query: ` 4725 -- start query 91 in stream 0 using template query91.tpl 4726 select 4727 cc_call_center_id Call_Center, 4728 cc_name Call_Center_Name, 4729 cc_manager Manager, 4730 sum(cr_net_loss) Returns_Loss 4731 from 4732 call_center, 4733 catalog_returns, 4734 date_dim, 4735 customer, 4736 customer_address, 4737 customer_demographics, 4738 household_demographics 4739 where 4740 cr_call_center_sk = cc_call_center_sk 4741 and cr_returned_date_sk = d_date_sk 4742 and cr_returning_customer_sk= c_customer_sk 4743 and cd_demo_sk = c_current_cdemo_sk 4744 and hd_demo_sk = c_current_hdemo_sk 4745 and ca_address_sk = c_current_addr_sk 4746 and d_year = 2000 4747 and d_moy = 12 4748 and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') 4749 or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) 4750 and hd_buy_potential like 'Unknown%' 4751 and ca_gmt_offset = -7 4752 group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status 4753 order by sum(cr_net_loss) desc;`, 4754 }, 4755 { 4756 Query: ` 4757 -- start query 92 in stream 0 using template query92.tpl 4758 select 4759 sum(ws_ext_discount_amt) as "Excess Discount Amount" 4760 from 4761 web_sales 4762 ,item 4763 ,date_dim 4764 where 4765 i_manufact_id = 714 4766 and i_item_sk = ws_item_sk 4767 and d_date between '2000-02-01' and 4768 (cast('2000-02-01' as date) + interval 90 day) 4769 and d_date_sk = ws_sold_date_sk 4770 and ws_ext_discount_amt 4771 > ( 4772 SELECT 4773 1.3 * avg(ws_ext_discount_amt) 4774 FROM 4775 web_sales 4776 ,date_dim 4777 WHERE 4778 ws_item_sk = i_item_sk 4779 and d_date between '2000-02-01' and 4780 (cast('2000-02-01' as date) + interval 90 day) 4781 and d_date_sk = ws_sold_date_sk 4782 ) 4783 order by sum(ws_ext_discount_amt) 4784 limit 100;`, 4785 }, 4786 { 4787 Query: ` 4788 -- start query 93 in stream 0 using template query93.tpl 4789 select ss_customer_sk 4790 ,sum(act_sales) sumsales 4791 from (select ss_item_sk 4792 ,ss_ticket_number 4793 ,ss_customer_sk 4794 ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price 4795 else (ss_quantity*ss_sales_price) end act_sales 4796 from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk 4797 and sr_ticket_number = ss_ticket_number) 4798 ,reason 4799 where sr_reason_sk = r_reason_sk 4800 and r_reason_desc = 'reason 58') t 4801 group by ss_customer_sk 4802 order by sumsales, ss_customer_sk 4803 limit 100;`, 4804 }, 4805 { 4806 Query: ` 4807 -- start query 94 in stream 0 using template query94.tpl 4808 select 4809 count(distinct ws_order_number) as "order count" 4810 ,sum(ws_ext_ship_cost) as "total shipping cost" 4811 ,sum(ws_net_profit) as "total net profit" 4812 from 4813 web_sales ws1 4814 ,date_dim 4815 ,customer_address 4816 ,web_site 4817 where 4818 d_date between '2002-5-01' and 4819 (cast('2002-5-01' as date) + interval 60 day) 4820 and ws1.ws_ship_date_sk = d_date_sk 4821 and ws1.ws_ship_addr_sk = ca_address_sk 4822 and ca_state = 'OK' 4823 and ws1.ws_web_site_sk = web_site_sk 4824 and web_company_name = 'pri' 4825 and exists (select * 4826 from web_sales ws2 4827 where ws1.ws_order_number = ws2.ws_order_number 4828 and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) 4829 and not exists(select * 4830 from web_returns wr1 4831 where ws1.ws_order_number = wr1.wr_order_number) 4832 order by count(distinct ws_order_number) 4833 limit 100;`, 4834 }, 4835 { 4836 Query: ` 4837 -- start query 95 in stream 0 using template query95.tpl 4838 with ws_wh as 4839 (select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 4840 from web_sales ws1,web_sales ws2 4841 where ws1.ws_order_number = ws2.ws_order_number 4842 and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) 4843 select 4844 count(distinct ws_order_number) as "order count" 4845 ,sum(ws_ext_ship_cost) as "total shipping cost" 4846 ,sum(ws_net_profit) as "total net profit" 4847 from 4848 web_sales ws1 4849 ,date_dim 4850 ,customer_address 4851 ,web_site 4852 where 4853 d_date between '2001-4-01' and 4854 (cast('2001-4-01' as date) + interval 60 day) 4855 and ws1.ws_ship_date_sk = d_date_sk 4856 and ws1.ws_ship_addr_sk = ca_address_sk 4857 and ca_state = 'VA' 4858 and ws1.ws_web_site_sk = web_site_sk 4859 and web_company_name = 'pri' 4860 and ws1.ws_order_number in (select ws_order_number 4861 from ws_wh) 4862 and ws1.ws_order_number in (select wr_order_number 4863 from web_returns,ws_wh 4864 where wr_order_number = ws_wh.ws_order_number) 4865 order by count(distinct ws_order_number) 4866 limit 100;`, 4867 }, 4868 { 4869 Query: ` 4870 -- start query 96 in stream 0 using template query96.tpl 4871 select count(*) 4872 from store_sales 4873 ,household_demographics 4874 ,time_dim, store 4875 where ss_sold_time_sk = time_dim.t_time_sk 4876 and ss_hdemo_sk = household_demographics.hd_demo_sk 4877 and ss_store_sk = s_store_sk 4878 and time_dim.t_hour = 8 4879 and time_dim.t_minute >= 30 4880 and household_demographics.hd_dep_count = 0 4881 and store.s_store_name = 'ese' 4882 order by count(*) 4883 limit 100;`, 4884 }, 4885 { 4886 Query: ` 4887 -- start query 97 in stream 0 using template query97.tpl 4888 with ssci as ( 4889 select ss_customer_sk customer_sk 4890 ,ss_item_sk item_sk 4891 from store_sales,date_dim 4892 where ss_sold_date_sk = d_date_sk 4893 and d_month_seq between 1199 and 1199 + 11 4894 group by ss_customer_sk 4895 ,ss_item_sk), 4896 csci as( 4897 select cs_bill_customer_sk customer_sk 4898 ,cs_item_sk item_sk 4899 from catalog_sales,date_dim 4900 where cs_sold_date_sk = d_date_sk 4901 and d_month_seq between 1199 and 1199 + 11 4902 group by cs_bill_customer_sk 4903 ,cs_item_sk) 4904 select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only 4905 ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only 4906 ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog 4907 from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk 4908 and ssci.item_sk = csci.item_sk) 4909 limit 100;`, 4910 }, 4911 { 4912 Query: ` 4913 -- start query 98 in stream 0 using template query98.tpl 4914 select i_item_id 4915 ,i_item_desc 4916 ,i_category 4917 ,i_class 4918 ,i_current_price 4919 ,sum(ss_ext_sales_price) as itemrevenue 4920 ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over 4921 (partition by i_class) as revenueratio 4922 from 4923 store_sales 4924 ,item 4925 ,date_dim 4926 where 4927 ss_item_sk = i_item_sk 4928 and i_category in ('Men', 'Sports', 'Jewelry') 4929 and ss_sold_date_sk = d_date_sk 4930 and d_date between cast('1999-02-05' as date) 4931 and (cast('1999-02-05' as date) + interval 30 day) 4932 group by 4933 i_item_id 4934 ,i_item_desc 4935 ,i_category 4936 ,i_class 4937 ,i_current_price 4938 order by 4939 i_category 4940 ,i_class 4941 ,i_item_id 4942 ,i_item_desc 4943 ,revenueratio;`, 4944 }, 4945 { 4946 Query: ` 4947 -- start query 99 in stream 0 using template query99.tpl 4948 select 4949 substr(w_warehouse_name,1,20) 4950 ,sm_type 4951 ,cc_name 4952 ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30 days" 4953 ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and 4954 (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31-60 days" 4955 ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and 4956 (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61-90 days" 4957 ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and 4958 (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91-120 days" 4959 ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as ">120 days" 4960 from 4961 catalog_sales 4962 ,warehouse 4963 ,ship_mode 4964 ,call_center 4965 ,date_dim 4966 where 4967 d_month_seq between 1194 and 1194 + 11 4968 and cs_ship_date_sk = d_date_sk 4969 and cs_warehouse_sk = w_warehouse_sk 4970 and cs_ship_mode_sk = sm_ship_mode_sk 4971 and cs_call_center_sk = cc_call_center_sk 4972 group by 4973 substr(w_warehouse_name,1,20) 4974 ,sm_type 4975 ,cc_name 4976 order by substr(w_warehouse_name,1,20) 4977 ,sm_type 4978 ,cc_name 4979 limit 100;`, 4980 }, 4981 }