Project: StarRocks (App Definition and Development / Database)
File: tpc_ds_99_sql.md

displayed_sidebar: "Chinese" ```sql -- query 1 with customertotalreturn as (select srcustomersk as ctrcustomersk ,srstoresk as ctrstoresk ,sum(SRRETURNAMT) as ctrtotalreturn from store_returns ,date_dim where srreturneddatesk = ddate_sk and d_year =2000 group by srcustomersk ,srstoresk) select ccustomerid from customertotalreturn ctr1 ,store ,customer where ctr1.ctrtotalreturn > (select avg(ctrtotalreturn)*1.2 from customertotalreturn ctr2 where ctr1.ctrstoresk = ctr2.ctrstoresk) and sstoresk = ctr1.ctrstoresk and s_state = 'TN' and ctr1.ctrcustomersk = ccustomersk order by ccustomerid limit 100; -- query 2 with wscs as (select solddatesk ,sales_price from (select wssolddatesk solddate_sk ,wsextsalesprice salesprice from web_sales union all select cssolddatesk solddate_sk ,csextsalesprice salesprice from catalog_sales) t), wswscs as (select dweekseq, sum(case when (ddayname='Sunday') then salesprice else null end) sunsales, sum(case when (ddayname='Monday') then salesprice else null end) monsales, sum(case when (ddayname='Tuesday') then salesprice else null end) tuesales, sum(case when (ddayname='Wednesday') then salesprice else null end) wedsales, sum(case when (ddayname='Thursday') then salesprice else null end) thusales, sum(case when (ddayname='Friday') then salesprice else null end) frisales, sum(case when (ddayname='Saturday') then salesprice else null end) satsales from wscs ,date_dim where ddatesk = solddatesk group by dweekseq) select dweekseq1 ,round(sunsales1/sunsales2,2) ,round(monsales1/monsales2,2) ,round(tuesales1/tuesales2,2) ,round(wedsales1/wedsales2,2) ,round(thusales1/thusales2,2) ,round(frisales1/frisales2,2) ,round(satsales1/satsales2,2) from (select wswscs.dweekseq dweekseq1 ,sunsales sunsales1 ,monsales monsales1 ,tuesales tuesales1 ,wedsales wedsales1 ,thusales thusales1 ,frisales frisales1 ,satsales satsales1 from wswscs,date_dim where datedim.dweekseq = wswscs.dweek_seq and d_year = 2001) y, (select wswscs.dweekseq dweekseq2 ,sunsales sunsales2 ,monsales monsales2 ,tuesales tuesales2 ,wedsales wedsales2 ,thusales thusales2 ,frisales frisales2 ,satsales satsales2 from wswscs ,date_dim where datedim.dweekseq = wswscs.dweek_seq and d_year = 2001+1) z where dweekseq1=dweekseq2-53 order by dweekseq1; -- query 3 select dt.d_year ,item.ibrandid brand_id ,item.i_brand brand ,sum(ssextsalesprice) sumagg from date_dim dt ,store_sales ,item where dt.ddatesk = storesales.sssolddatesk and storesales.ssitemsk = item.iitem_sk and item.imanufactid = 128 and dt.d_moy=11 group by dt.d_year ,item.i_brand ,item.ibrandid order by dt.d_year ,sum_agg desc ,brand_id limit 100; -- query 4 with year_total as ( select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,cpreferredcustflag customerpreferredcustflag ,cbirthcountry customerbirthcountry ,clogin customerlogin ,cemailaddress customeremailaddress ,d_year dyear ,sum(((ssextlistprice-ssextwholesalecost-ssextdiscountamt)+ssextsalesprice)/2) year_total ,'s' sale_type from customer ,store_sales ,date_dim where ccustomersk = sscustomersk and sssolddatesk = ddate_sk group by ccustomerid ,cfirstname ,clastname ,cpreferredcust_flag ,cbirthcountry ,c_login ,cemailaddress ,d_year union all select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,cpreferredcustflag customerpreferredcustflag ,cbirthcountry customerbirthcountry ,clogin customerlogin ,cemailaddress customeremailaddress ,d_year dyear ,sum((((csextlistprice-csextwholesalecost-csextdiscountamt)+csextsalesprice)/2) ) year_total ,'c' sale_type from customer ,catalog_sales ,date_dim where ccustomersk = csbillcustomer_sk and cssolddatesk = ddate_sk group by ccustomerid ,cfirstname ,clastname ,cpreferredcust_flag ,cbirthcountry ,c_login ,cemailaddress ,d_year union all select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,cpreferredcustflag customerpreferredcustflag ,cbirthcountry customerbirthcountry ,clogin customerlogin ,cemailaddress customeremailaddress ,d_year dyear ,sum((((wsextlistprice-wsextwholesalecost-wsextdiscountamt)+wsextsalesprice)/2) ) year_total ,'w' sale_type from customer ,web_sales ,date_dim where ccustomersk = wsbillcustomer_sk and wssolddatesk = ddate_sk group by ccustomerid ,cfirstname ,clastname ,cpreferredcust_flag ,cbirthcountry ,c_login ,cemailaddress ,d_year ) select tssecyear.customer_id ,tssecyear.customerfirstname ,tssecyear.customerlastname ,tssecyear.customerpreferredcust_flag from yeartotal ts_firstyear ,yeartotal ts_secyear ,yeartotal tc_firstyear ,yeartotal tc_secyear ,yeartotal tw_firstyear ,yeartotal tw_secyear where tssecyear.customerid = tsfirstyear.customerid and tsfirstyear.customerid = tcsecyear.customerid and tsfirstyear.customerid = tcfirstyear.customerid and tsfirstyear.customerid = twfirstyear.customerid and tsfirstyear.customerid = twsecyear.customerid and tsfirstyear.sale_type = 's' and tcfirstyear.sale_type = 'c' and twfirstyear.sale_type = 'w' and tssecyear.sale_type = 's' and tcsecyear.sale_type = 'c' and twsecyear.sale_type = 'w' and tsfirstyear.dyear = 2001 and tssecyear.dyear = 2001+1 and tcfirstyear.dyear = 2001 and tcsecyear.dyear = 2001+1 and twfirstyear.dyear = 2001 and twsecyear.dyear = 2001+1 and tsfirstyear.year_total > 0 and tcfirstyear.year_total > 0 and twfirstyear.year_total > 0 and case when tcfirstyear.yeartotal > 0 then tcsecyear.yeartotal / tcfirstyear.year_total else null end > case when tsfirstyear.yeartotal > 0 then tssecyear.yeartotal / tsfirstyear.year_total else null end and case when tcfirstyear.yeartotal > 0 then tcsecyear.yeartotal / tcfirstyear.year_total else null end > case when twfirstyear.yeartotal > 0 then twsecyear.yeartotal / twfirstyear.year_total else null end order by tssecyear.customer_id ,tssecyear.customerfirstname ,tssecyear.customerlastname

limit 100; -- query 5 with ssr as (select sstoreid, sum(sales_price) as sales, sum(profit) as profit, sum(return_amt) as returns, sum(netloss) as profitloss from ( select ssstoresk as store_sk, sssolddatesk as datesk, ssextsalesprice as salesprice, ssnetprofit as profit, cast(0 as decimal(7,2)) as return_amt, cast(0 as decimal(7,2)) as net_loss from store_sales union all select srstoresk as store_sk, srreturneddatesk as datesk, cast(0 as decimal(7,2)) as sales_price, cast(0 as decimal(7,2)) as profit, srreturnamt as return_amt, srnetloss as net_loss from store_returns ) salesreturns, date_dim, store where datesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 14) and storesk = sstore_sk group by sstoreid) , csr as (select cpcatalogpage_id, sum(sales_price) as sales, sum(profit) as profit, sum(return_amt) as returns, sum(netloss) as profitloss from ( select cscatalogpagesk as pagesk, cssolddatesk as datesk, csextsalesprice as salesprice, csnetprofit as profit, cast(0 as decimal(7,2)) as return_amt, cast(0 as decimal(7,2)) as net_loss from catalog_sales union all select crcatalogpagesk as pagesk, crreturneddatesk as datesk, cast(0 as decimal(7,2)) as sales_price, cast(0 as decimal(7,2)) as profit, crreturnamount as return_amt, crnetloss as net_loss from catalog_returns ) salesreturns, date_dim, catalog_page where datesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 14) and pagesk = cpcatalogpagesk group by cpcatalogpage_id) , wsr as (select websiteid, sum(sales_price) as sales, sum(profit) as profit, sum(return_amt) as returns, sum(netloss) as profitloss from ( select wswebsitesk as wsrwebsitesk, wssolddatesk as datesk, wsextsalesprice as salesprice, wsnetprofit as profit, cast(0 as decimal(7,2)) as return_amt, cast(0 as decimal(7,2)) as net_loss from web_sales union all select wswebsitesk as wsrwebsitesk, wrreturneddatesk as datesk, cast(0 as decimal(7,2)) as sales_price, cast(0 as decimal(7,2)) as profit, wrreturnamt as return_amt, wrnetloss as net_loss from webreturns left outer join websales on ( writemsk = wsitemsk and wrordernumber = wsordernumber) ) salesreturns, date_dim, web_site where datesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 14) and wsrwebsitesk = website_sk group by websiteid) select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit from (select 'store channel' as channel , 'store' || sstoreid as id , sales , returns , (profit - profit_loss) as profit from ssr union all select 'catalog channel' as channel , 'catalogpage' || cpcatalogpageid as id , sales , returns , (profit - profit_loss) as profit from csr union all select 'web channel' as channel , 'website' || website_id as id , sales , returns , (profit - profit_loss) as profit from wsr ) x group by rollup (channel, id) order by channel ,id limit 100; -- query 6 select a.ca_state state, count(*) cnt from customer_address a ,customer c ,store_sales s ,date_dim d ,item i where a.caaddresssk = c.ccurrentaddr_sk and c.ccustomersk = s.sscustomersk and s.sssolddatesk = d.ddate_sk and s.ssitemsk = i.iitemsk and d.dmonthseq = (select distinct (dmonthseq) from date_dim where d_year = 2001 and d_moy = 1 ) and i.icurrentprice > 1.2 * (select avg(j.icurrentprice) from item j where j.icategory = i.icategory) group by a.ca_state having count(*) >= 10 order by cnt,

limit 100; -- query 7 select iitemid, avg(ss_quantity) agg1, avg(sslistprice) agg2, avg(sscouponamt) agg3, avg(sssalesprice) agg4 from storesales, customerdemographics, date_dim, item, promotion where sssolddatesk = ddate_sk and ssitemsk = iitemsk and sscdemosk = cddemosk and sspromosk = ppromosk and cd_gender = 'M' and cdmaritalstatus = 'S' and cdeducationstatus = 'College' and (pchannelemail = 'N' or pchannelevent = 'N') and d_year = 2000 group by iitemid order by iitemid limit 100; -- query 8 select sstorename ,sum(ssnetprofit) from store_sales ,date_dim ,store, (select ca_zip from ( SELECT substr(cazip,1,5) cazip FROM customer_address WHERE substr(ca_zip,1,5) IN ( '24128','76232','65084','87816','83926','77556','20548','26231','43848','15126', '91137','61265','98294','25782','17920','18426','98235','40081','84093','28577', '55565','17183','54601','67897','22752','86284','18376','38607','45200','21756', '29741','96765','23932','89360','29839','25989','28898','91068','72550','10390', '18845','47770','82636','41367','76638','86198','81312','37126','39192','88424', '72175','81426','53672','10445','42666','66864','66708','41248','48583','82276', '18842','78890','49448','14089','38122','34425','79077','19849','43285','39861', '66162','77610','13695','99543','83444','83041','12305','57665','68341','25003', '57834','62878','49130','81096','18840','27700','23470','50412','21195','16021', '76107','71954','68309','18119','98359','64544','10336','86379','27068','39736', '98569','28915','24206','56529','57647','54917','42961','91110','63981','14922', '36420','23006','67467','32754','30903','20260','31671','51798','72325','85816', '68621','13955','36446','41766','68806','16725','15146','22744','35850','88086', '51649','18270','52867','39972','96976','63792','11376','94898','13595','10516', '90225','58943','39371','94945','28587','96576','57855','28488','26105','83933', '25858','34322','44438','73171','30122','34102','22685','71256','78451','54364', '13354','45375','40558','56458','28286','45266','47305','69399','83921','26233', '11101','15371','69913','35942','15882','25631','24610','44165','99076','33786', '70738','26653','14328','72305','62496','22152','10144','64147','48425','14663', '21076','18799','30450','63089','81019','68893','24996','51200','51211','45692', '92712','70466','79994','22437','25280','38935','71791','73134','56571','14060', '19505','72425','56575','74351','68786','51650','20004','18383','76614','11634', '18906','15765','41368','73241','76698','78567','97189','28545','76231','75691', '22246','51061','90578','56691','68014','51103','94167','57047','14867','73520', '15734','63435','25733','35474','24676','94627','53535','17879','15559','53268', '59166','11928','59402','33282','45721','43933','68101','33515','36634','71286', '19736','58058','55253','67473','41918','19515','36495','19430','22351','77191', '91393','49156','50298','87501','18652','53179','18767','63193','23968','65164', '68880','21286','72823','58470','67301','13394','31016','70372','67030','40604', '24317','45748','39127','26065','77721','31029','31880','60576','24671','45549', '13376','50016','33123','19769','22927','97789','46081','72151','15723','46136', '51949','68100','96888','64528','14171','79777','28709','11489','25103','32213', '78668','22245','15798','27156','37930','62971','21337','51622','67853','10567', '38415','15455','58263','42029','60279','37125','56240','88190','50308','26859', '64457','89091','82136','62377','36233','63837','58078','17043','30010','60099', '28810','98025','29178','87343','73273','30469','64034','39516','86057','21309', '90257','67875','40162','11356','73650','61810','72013','30431','22461','19512', '13375','55307','30625','83849','68908','26689','96451','38193','46820','88885', '84935','69035','83144','47537','56616','94983','48033','69952','25486','61547', '27385','61860','58048','56910','16807','17871','35258','31387','35458','35576') intersect select ca_zip from (SELECT substr(cazip,1,5) cazip,count(*) cnt FROM customer_address, customer WHERE caaddresssk = ccurrentaddr_sk and cpreferredcust_flag='Y' group by ca_zip having count(*) > 10)A1)A2) V1 where ssstoresk = sstoresk and sssolddatesk = ddate_sk and dqoy = 2 and dyear = 1998 and (substr(szip,1,2) = substr(V1.cazip,1,2)) group by sstorename order by sstorename limit 100; -- query 9 select case when (select count(*) from store_sales where ss_quantity between 1 and 20) > 74219 then (select avg(ssextdiscount_amt) from store_sales where ss_quantity between 1 and 20) else (select avg(ssnetpaid) from store_sales where ss_quantity between 1 and 20) end bucket1 , case when (select count(*) from store_sales where ss_quantity between 21 and 40) > 122840 then (select avg(ssextdiscount_amt) from store_sales where ss_quantity between 21 and 40) else (select avg(ssnetpaid) from store_sales where ss_quantity between 21 and 40) end bucket2, case when (select count(*) from store_sales where ss_quantity between 41 and 60) > 56580 then (select avg(ssextdiscount_amt) from store_sales where ss_quantity between 41 and 60) else (select avg(ssnetpaid) from store_sales where ss_quantity between 41 and 60) end bucket3, case when (select count(*) from store_sales where ss_quantity between 61 and 80) > 10097 then (select avg(ssextdiscount_amt) from store_sales where ss_quantity between 61 and 80) else (select avg(ssnetpaid) from store_sales where ss_quantity between 61 and 80) end bucket4, case when (select count(*) from store_sales where ss_quantity between 81 and 100) > 165306 then (select avg(ssextdiscount_amt) from store_sales where ss_quantity between 81 and 100) else (select avg(ssnetpaid) from store_sales where ss_quantity between 81 and 100) end bucket5 from reason where rreasonsk = 1 ; -- query 10 select cd_gender, cdmaritalstatus, cdeducationstatus, count(*) cnt1, cdpurchaseestimate, count(*) cnt2, cdcreditrating, count(*) cnt3, cddepcount, count(*) cnt4, cddepemployed_count, count(*) cnt5, cddepcollege_count, count(*) cnt6 from customer c,customeraddress ca,customerdemographics where c.ccurrentaddrsk = ca.caaddress_sk and ca_county in ('Rush County','Toole County','Jefferson County','Dona Ana County','La Porte County') and cddemosk = c.ccurrentcdemo_sk and exists (select * from storesales,datedim where c.ccustomersk = sscustomersk and sssolddatesk = ddate_sk and d_year = 2002 and d_moy between 1 and 1+3) and exists (select * from ( select wsbillcustomersk as customersk, dyear,dmoy from websales, datedim where wssolddatesk = ddate_sk and d_year = 2002 and d_moy between 1 and 1+3 union all select csshipcustomersk as customersk, dyear, dmoy from catalogsales, datedim where cssolddatesk = ddate_sk and d_year = 2002 and d_moy between 1 and 1+3 ) x where c.ccustomersk = customer_sk) group by cd_gender, cdmaritalstatus, cdeducationstatus, cdpurchaseestimate, cdcreditrating, cddepcount, cddepemployed_count, cddepcollege_count order by cd_gender, cdmaritalstatus, cdeducationstatus, cdpurchaseestimate, cdcreditrating, cddepcount, cddepemployed_count, cddepcollege_count limit 100; -- query 11 with year_total as ( select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,cpreferredcustflag customerpreferredcustflag ,cbirthcountry customerbirthcountry ,clogin customerlogin ,cemailaddress customeremailaddress ,d_year dyear ,sum(ssextlistprice-ssextdiscountamt) year_total ,'s' sale_type from customer ,store_sales ,date_dim where ccustomersk = sscustomersk and sssolddatesk = ddate_sk group by ccustomerid ,cfirstname ,clastname ,cpreferredcust_flag ,cbirthcountry ,c_login ,cemailaddress ,d_year union all select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,cpreferredcustflag customerpreferredcustflag ,cbirthcountry customerbirthcountry ,clogin customerlogin ,cemailaddress customeremailaddress ,d_year dyear ,sum(wsextlistprice-wsextdiscountamt) year_total ,'w' sale_type from customer ,web_sales ,date_dim where ccustomersk = wsbillcustomer_sk and wssolddatesk = ddate_sk group by ccustomerid ,cfirstname ,clastname ,cpreferredcust_flag ,cbirthcountry ,c_login ,cemailaddress ,d_year ) select tssecyear.customer_id ,tssecyear.customerfirstname ,tssecyear.customerlastname ,tssecyear.customerpreferredcust_flag from yeartotal ts_firstyear ,yeartotal ts_secyear ,yeartotal tw_firstyear ,yeartotal tw_secyear where tssecyear.customerid = tsfirstyear.customerid and tsfirstyear.customerid = twsecyear.customerid and tsfirstyear.customerid = twfirstyear.customerid and tsfirstyear.sale_type = 's' and twfirstyear.sale_type = 'w' and tssecyear.sale_type = 's' and twsecyear.sale_type = 'w' and tsfirstyear.dyear = 2001 and

= 2001+1 and twfirstyear.dyear = 2001 and twsecyear.dyear = 2001+1 and tsfirstyear.year_total > 0 and twfirstyear.year_total > 0 and case when twfirstyear.yeartotal > 0 then twsecyear.yeartotal / twfirstyear.year_total else 0.0 end > case when tsfirstyear.yeartotal > 0 then tssecyear.yeartotal / tsfirstyear.year_total else 0.0 end order by tssecyear.customer_id ,tssecyear.customerfirstname ,tssecyear.customerlastname ,tssecyear.customerpreferredcust_flag limit 100; -- query 12 select iitemid ,iitemdesc ,i_category ,i_class ,icurrentprice ,sum(wsextsales_price) as itemrevenue ,sum(wsextsalesprice)*100/sum(sum(wsextsalesprice)) over (partition by i_class) as revenueratio from web_sales ,item ,date_dim where wsitemsk = iitemsk and i_category in ('Sports', 'Books', 'Home') and wssolddatesk = ddate_sk and d_date between cast('1999-02-22' as date) and date_add(cast('1999-02-22' as date), 30) group by iitemid ,iitemdesc ,i_category ,i_class ,icurrentprice order by i_category ,i_class ,iitemid ,iitemdesc ,revenueratio limit 100; -- query 13 select avg(ss_quantity) ,avg(ssextsales_price) ,avg(ssextwholesale_cost) ,sum(ssextwholesale_cost) from store_sales ,store ,customer_demographics ,household_demographics ,customer_address ,date_dim where sstoresk = ssstoresk and sssolddatesk = ddatesk and dyear = 2001 and((sshdemosk=hddemosk and cddemosk = sscdemosk and cdmaritalstatus = 'M' and cdeducationstatus = 'Advanced Degree' and sssalesprice between 100.00 and 150.00 and hddepcount = 3 )or (sshdemosk=hddemosk and cddemosk = sscdemosk and cdmaritalstatus = 'S' and cdeducationstatus = 'College' and sssalesprice between 50.00 and 100.00 and hddepcount = 1 ) or (sshdemosk=hddemosk and cddemosk = sscdemosk and cdmaritalstatus = 'W' and cdeducationstatus = '2 yr Degree' and sssalesprice between 150.00 and 200.00 and hddepcount = 1 )) and((ssaddrsk = caaddresssk and ca_country = 'United States' and ca_state in ('TX', 'OH', 'TX') and ssnetprofit between 100 and 200 ) or (ssaddrsk = caaddresssk and ca_country = 'United States' and ca_state in ('OR', 'NM', 'KY') and ssnetprofit between 150 and 300 ) or (ssaddrsk = caaddresssk and ca_country = 'United States' and ca_state in ('VA', 'TX', 'MS') and ssnetprofit between 50 and 250 )) ; -- query 14 with cross_items as (select iitemsk ssitemsk from item, (select iss.ibrandid brand_id ,iss.iclassid class_id ,iss.icategoryid category_id from store_sales ,item iss ,date_dim d1 where ssitemsk = iss.iitemsk and sssolddatesk = d1.ddate_sk and d1.d_year between 1999 AND 1999 + 2 intersect select ics.ibrandid ,ics.iclassid ,ics.icategoryid from catalog_sales ,item ics ,date_dim d2 where csitemsk = ics.iitemsk and cssolddatesk = d2.ddate_sk and d2.d_year between 1999 AND 1999 + 2 intersect select iws.ibrandid ,iws.iclassid ,iws.icategoryid from web_sales ,item iws ,date_dim d3 where wsitemsk = iws.iitemsk and wssolddatesk = d3.ddate_sk and

between 1999 AND 1999 + 2) t where ibrandid = brand_id and iclassid = class_id and icategoryid = category_id ), avg_sales as (select avg(quantity*listprice) averagesales from (select ss_quantity quantity ,sslistprice list_price from store_sales ,date_dim where sssolddatesk = ddate_sk and d_year between 1999 and 1999 + 2 union all select cs_quantity quantity ,cslistprice list_price from catalog_sales ,date_dim where cssolddatesk = ddate_sk and d_year between 1999 and 1999 + 2 union all select ws_quantity quantity ,wslistprice list_price from web_sales ,date_dim where wssolddatesk = ddate_sk and d_year between 1999 and 1999 + 2) x) select channel, ibrandid,iclassid,icategoryid,sum(sales), sum(number_sales) from( select 'store' channel, ibrandid,iclassid ,icategoryid,sum(ssquantity*sslist_price) sales , count(*) number_sales from store_sales ,item ,date_dim where ssitemsk in (select ssitemsk from cross_items) and ssitemsk = iitemsk and sssolddatesk = ddate_sk and d_year = 1999+2 and d_moy = 11 group by ibrandid,iclassid,icategoryid having sum(ssquantity*sslistprice) > (select averagesales from avg_sales) union all select 'catalog' channel, ibrandid,iclassid,icategoryid, sum(csquantity*cslistprice) sales, count(*) numbersales from catalog_sales ,item ,date_dim where csitemsk in (select ssitemsk from cross_items) and csitemsk = iitemsk and cssolddatesk = ddate_sk and d_year = 1999+2 and d_moy = 11 group by ibrandid,iclassid,icategoryid having sum(csquantity*cslistprice) > (select averagesales from avg_sales) union all select 'web' channel, ibrandid,iclassid,icategoryid, sum(wsquantity*wslistprice) sales , count(*) numbersales from web_sales ,item ,date_dim where wsitemsk in (select ssitemsk from cross_items) and wsitemsk = iitemsk and wssolddatesk = ddate_sk and d_year = 1999+2 and d_moy = 11 group by ibrandid,iclassid,icategoryid having sum(wsquantity*wslistprice) > (select averagesales from avg_sales) ) y group by rollup (channel, ibrandid,iclassid,icategoryid) order by channel,ibrandid,iclassid,icategoryid limit 100; with cross_items as (select iitemsk ssitemsk from item, (select iss.ibrandid brand_id ,iss.iclassid class_id ,iss.icategoryid category_id from store_sales ,item iss ,date_dim d1 where ssitemsk = iss.iitemsk and sssolddatesk = d1.ddate_sk and d1.d_year between 1999 AND 1999 + 2 intersect select ics.ibrandid ,ics.iclassid ,ics.icategoryid from catalog_sales ,item ics ,date_dim d2 where csitemsk = ics.iitemsk and cssolddatesk = d2.ddate_sk and d2.d_year between 1999 AND 1999 + 2 intersect select iws.ibrandid ,iws.iclassid ,iws.icategoryid from web_sales ,item iws ,date_dim d3 where wsitemsk = iws.iitemsk and wssolddatesk = d3.ddate_sk and d3.d_year between 1999 AND 1999 + 2) x where ibrandid = brand_id and iclassid = class_id and icategoryid = category_id ), avg_sales as (select avg(quantity*listprice) averagesales from (select ss_quantity quantity ,sslistprice list_price from store_sales ,date_dim where sssolddatesk = ddate_sk and d_year between 1999 and 1999 + 2 union all select cs_quantity quantity ,cslistprice list_price from catalog_sales ,date_dim where cssolddatesk = ddate_sk and d_year between 1999 and 1999 + 2 union all select ws_quantity quantity ,wslistprice list_price from web_sales ,date_dim where wssolddatesk = ddate_sk and d_year between 1999 and 1999 + 2) x) select thisyear.channel tychannel ,thisyear.ibrandid tybrand ,thisyear.iclassid tyclass ,thisyear.icategoryid tycategory ,thisyear.sales tysales ,thisyear.numbersales tynumbersales ,lastyear.channel lychannel ,lastyear.ibrandid lybrand ,lastyear.iclassid lyclass ,lastyear.icategoryid lycategory ,lastyear.sales lysales ,lastyear.numbersales lynumbersales from (select 'store' channel, ibrandid,iclassid,icategoryid ,sum(ssquantity*sslistprice) sales, count(*) numbersales from store_sales ,item ,date_dim where ssitemsk in (select ssitemsk from cross_items) and ssitemsk = iitemsk and sssolddatesk = ddate_sk and dweekseq = (select dweekseq from date_dim where d_year = 1999 + 1 and d_moy = 12 and d_dom = 11) group by ibrandid,iclassid,icategoryid having sum(ssquantity*sslistprice) > (select averagesales from avgsales)) thisyear, (select 'store' channel, ibrandid,iclassid ,icategoryid, sum(ssquantity*sslistprice) sales, count(*) numbersales from store_sales ,item ,date_dim where ssitemsk in (select ssitemsk from cross_items) and ssitemsk = iitemsk and sssolddatesk = ddate_sk and dweekseq = (select dweekseq from date_dim where d_year = 1999 and d_moy = 12 and d_dom = 11) group by ibrandid,iclassid,icategoryid having sum(ssquantity*sslistprice) > (select averagesales from avgsales)) lastyear where thisyear.ibrandid= lastyear.ibrandid and thisyear.iclassid = lastyear.iclassid and thisyear.icategoryid = lastyear.icategoryid order by thisyear.channel, thisyear.ibrandid, thisyear.iclassid, thisyear.icategoryid limit 100; -- query 15 select ca_zip ,sum(cssalesprice) from catalog_sales ,customer ,customer_address ,date_dim where csbillcustomersk = ccustomer_sk and ccurrentaddrsk = caaddress_sk and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') or ca_state in ('CA','WA','GA') or cssalesprice > 500) and cssolddatesk = ddate_sk and dqoy = 2 and dyear = 2001 group by ca_zip order by ca_zip limit 100; -- query 16 select count(distinct csordernumber) as "order count" ,sum(csextship_cost) as "total shipping cost" ,sum(csnetprofit) as "total net profit" from catalog_sales cs1 ,date_dim ,customer_address ,call_center where d_date between '2002-2-01' and date_add(cast('2002-2-01' as date), 60) and cs1.csshipdatesk = ddate_sk and cs1.csshipaddrsk = caaddress_sk and ca_state = 'GA' and cs1.cscallcentersk = cccallcentersk and cc_county in ('Williamson County', 'Williamson County', 'Williamson County', 'Williamson County', 'Williamson County') and exists (select * from catalog_sales cs2 where cs1.csordernumber = cs2.csordernumber and cs1.cswarehousesk <> cs2.cswarehousesk) and not exists(select * from catalog_returns cr1 where cs1.csordernumber = cr1.crordernumber) order by count(distinct csordernumber) limit 100; -- query 17 select iitemid ,iitemdesc ,s_state ,count(ssquantity) as storesales_quantitycount ,avg(ssquantity) as storesales_quantityave ,stddevsamp(ssquantity) as storesalesquantitystdev ,stddevsamp(ssquantity)/avg(ssquantity) as storesales_quantitycov ,count(srreturnquantity) as storereturnsquantitycount ,avg(srreturnquantity) as storereturnsquantityave ,stddevsamp(srreturnquantity) as storereturns_quantitystdev ,stddevsamp(srreturnquantity)/avg(srreturnquantity) as storereturns_quantitycov ,count(csquantity) as catalogsalesquantitycount ,avg(csquantity) as catalogsalesquantityave ,stddevsamp(csquantity) as catalogsalesquantitystdev ,stddevsamp(csquantity)/avg(csquantity) as catalogsales_quantitycov from store_sales ,store_returns ,catalog_sales ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,item where

= '2001Q1' and d1.ddatesk = sssolddate_sk and iitemsk = ssitemsk and sstoresk = ssstoresk and sscustomersk = srcustomersk and ssitemsk = sritemsk and ssticketnumber = srticketnumber and srreturneddatesk = d2.ddate_sk and d2.dquartername in ('2001Q1','2001Q2','2001Q3') and srcustomersk = csbillcustomer_sk and sritemsk = csitemsk and cssolddatesk = d3.ddate_sk and d3.dquartername in ('2001Q1','2001Q2','2001Q3') group by iitemid ,iitemdesc ,s_state order by iitemid ,iitemdesc ,s_state limit 100; -- query 18 select iitemid, ca_country, ca_state, ca_county, avg( cast(cs_quantity as decimal(12,2))) agg1, avg( cast(cslistprice as decimal(12,2))) agg2, avg( cast(cscouponamt as decimal(12,2))) agg3, avg( cast(cssalesprice as decimal(12,2))) agg4, avg( cast(csnetprofit as decimal(12,2))) agg5, avg( cast(cbirthyear as decimal(12,2))) agg6, avg( cast(cd1.cddepcount as decimal(12,2))) agg7 from catalogsales, customerdemographics cd1, customerdemographics cd2, customer, customeraddress, date_dim, item where cssolddatesk = ddate_sk and csitemsk = iitemsk and csbillcdemosk = cd1.cddemo_sk and csbillcustomersk = ccustomer_sk and cd1.cd_gender = 'F' and cd1.cdeducationstatus = 'Unknown' and ccurrentcdemosk = cd2.cddemo_sk and ccurrentaddrsk = caaddress_sk and cbirthmonth in (1, 6, 8, 9, 12, 2) and d_year = 1998 and ca_state in ('MS','IN','ND' ,'OK','NM','VA','MS') group by rollup (iitemid, cacountry, castate, ca_county) order by ca_country, ca_state, ca_county, iitemid limit 100; -- query 19 select ibrandid brandid, ibrand brand, imanufactid, i_manufact, sum(ssextsalesprice) extprice from datedim, storesales, item,customer,customer_address,store where ddatesk = sssolddate_sk and ssitemsk = iitemsk and imanagerid=8 and d_moy=11 and d_year=1998 and sscustomersk = ccustomersk and ccurrentaddrsk = caaddress_sk and substr(cazip,1,5) <> substr(szip,1,5) and ssstoresk = sstoresk group by i_brand ,ibrandid ,imanufactid ,i_manufact order by ext_price desc ,i_brand ,ibrandid ,imanufactid ,i_manufact limit 100 ; -- query 20 select iitemid ,iitemdesc ,i_category ,i_class ,icurrentprice ,sum(csextsales_price) as itemrevenue ,sum(csextsalesprice)*100/sum(sum(csextsalesprice)) over (partition by i_class) as revenueratio from catalog_sales ,item ,date_dim where csitemsk = iitemsk and i_category in ('Sports','Books','Home') and cssolddatesk = ddate_sk and d_date between cast('1999-02-22' as date) and date_add(cast('1999-02-22' as date), 30) group by iitemid ,iitemdesc ,i_category ,i_class ,icurrentprice order by i_category ,i_class ,iitemid ,iitemdesc ,revenueratio limit 100; -- query 21 select * from(select wwarehousename ,iitemid ,sum(case when (cast(d_date as date) < cast ('2000-03-11' as date)) then invquantityon_hand else 0 end) as inv_before ,sum(case when (cast(d_date as date) >= cast ('2000-03-11' as date)) then invquantityon_hand else 0 end) as inv_after from inventory ,warehouse ,item ,date_dim where icurrentprice between 0.99 and 1.49 and iitemsk = invitemsk and invwarehousesk = wwarehousesk and invdatesk = ddatesk and ddate between dateadd(cast ('2000-03-11' as date), -30) and date_add(cast ('2000-03-11' as date), 30) group by wwarehousename, iitemid) x where (case when inv_before > 0 then invafter / invbefore else null end) between 2.0/3.0 and 3.0/2.0 order by wwarehousename ,iitemid limit 100; -- query 22 select iproductname ,i_brand ,i_class ,i_category ,avg(invquantityon_hand) qoh from inventory ,date_dim ,item where invdatesk=ddatesk and invitemsk=iitemsk and dmonthseq between 1200 and 1200 + 11 group by rollup(iproductname ,i_brand ,i_class ,i_category) order by qoh, iproductname, ibrand, iclass, i_category limit 100; -- query 23 with frequentssitems as (select substr(iitemdesc,1,30) itemdesc,iitemsk itemsk,ddate solddate,count(*) cnt from store_sales ,date_dim ,item where sssolddatesk = ddate_sk and ssitemsk = iitemsk and d_year in (2000,2000+1,2000+2,2000+3) group by substr(iitemdesc,1,30),iitemsk,d_date having count(*) >4), maxstoresales as (select max(csales) tpcds_cmax from (select ccustomersk,sum(ssquantity*sssales_price) csales from store_sales ,customer ,date_dim where sscustomersk = ccustomersk and sssolddatesk = ddate_sk and d_year in (2000,2000+1,2000+2,2000+3) group by ccustomersk) t1), bestsscustomer as (select ccustomersk,sum(ssquantity*sssales_price) ssales from store_sales ,customer where sscustomersk = ccustomersk group by ccustomersk having sum(ssquantity*sssales_price) >

* (select from maxstoresales)) select sum(sales) from (select csquantity*cslist_price sales from catalog_sales ,date_dim where d_year = 2000 and d_moy = 2 and cssolddatesk = ddate_sk and csitemsk in (select itemsk from frequentss_items) and csbillcustomersk in (select ccustomersk from bestss_customer) union all select wsquantity*wslist_price sales from web_sales ,date_dim where d_year = 2000 and d_moy = 2 and wssolddatesk = ddate_sk and wsitemsk in (select itemsk from frequentss_items) and wsbillcustomersk in (select ccustomersk from bestss_customer)) t2 limit 100; with frequentssitems as (select substr(iitemdesc,1,30) itemdesc,iitemsk itemsk,ddate solddate,count(*) cnt from store_sales ,date_dim ,item where sssolddatesk = ddate_sk and ssitemsk = iitemsk and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) group by substr(iitemdesc,1,30),iitemsk,d_date having count(*) >4), maxstoresales as (select max(csales) tpcds_cmax from (select ccustomersk,sum(ssquantity*sssales_price) csales from store_sales ,customer ,date_dim where sscustomersk = ccustomersk and sssolddatesk = ddate_sk and d_year in (2000,2000+1,2000+2,2000+3) group by ccustomersk) t1), bestsscustomer as (select ccustomersk,sum(ssquantity*sssales_price) ssales from store_sales ,customer where sscustomersk = ccustomersk group by ccustomersk having sum(ssquantity*sssales_price) > (50/100.0) * (select from maxstoresales)) select clastname,cfirstname,sales from (select clastname,cfirstname,sum(csquantity*cslist_price) sales from catalog_sales ,customer ,date_dim where d_year = 2000 and d_moy = 2 and cssolddatesk = ddate_sk and csitemsk in (select itemsk from frequentss_items) and csbillcustomersk in (select ccustomersk from bestss_customer) and csbillcustomersk = ccustomer_sk group by clastname,cfirstname union all select clastname,cfirstname,sum(wsquantity*wslist_price) sales from web_sales ,customer ,date_dim where d_year = 2000 and d_moy = 2 and wssolddatesk = ddate_sk and wsitemsk in (select itemsk from frequentss_items) and wsbillcustomersk in (select ccustomersk from bestss_customer) and wsbillcustomersk = ccustomer_sk group by clastname,cfirstname) t2 order by clastname,cfirstname,sales limit 100; -- query 24 with ssales as (select clastname ,cfirstname ,sstorename ,ca_state ,s_state ,i_color ,icurrentprice ,imanagerid ,i_units ,i_size ,sum(ssnetpaid) netpaid from store_sales ,store_returns ,store ,item ,customer ,customer_address where ssticketnumber = srticketnumber and ssitemsk = sritemsk and sscustomersk = ccustomersk and ssitemsk = iitemsk and ssstoresk = sstoresk and ccurrentaddrsk = caaddress_sk and cbirthcountry <> upper(ca_country) and szip = cazip and smarketid=8 group by clastname ,cfirstname ,sstorename ,ca_state ,s_state ,i_color ,icurrentprice ,imanagerid ,i_units ,i_size) select clastname ,cfirstname ,sstorename ,sum(netpaid) paid from ssales where i_color = 'peach' group by clastname ,cfirstname ,sstorename having sum(netpaid) > (select 0.05*avg(netpaid) from ssales) order by clastname ,cfirstname ,sstorename ; with ssales as (select clastname ,cfirstname ,sstorename ,ca_state ,s_state ,i_color ,icurrentprice ,imanagerid ,i_units ,i_size ,sum(ssnetpaid) netpaid from store_sales ,store_returns ,store ,item ,customer ,customer_address where ssticketnumber = srticketnumber and ssitemsk = sritemsk and sscustomersk = ccustomersk and ssitemsk = iitemsk and ssstoresk = sstoresk and ccurrentaddrsk = caaddress_sk and cbirthcountry <> upper(ca_country) and szip = cazip and smarketid = 8 group by clastname ,cfirstname ,sstorename ,ca_state ,s_state ,i_color ,icurrentprice ,imanagerid ,i_units ,i_size) select clastname ,cfirstname ,sstorename ,sum(netpaid) paid from ssales where i_color = 'saddle' group by clastname ,cfirstname ,sstorename having sum(netpaid) > (select 0.05*avg(netpaid) from ssales) order by clastname ,cfirstname ,sstorename ; -- query 25 select iitemid ,iitemdesc ,sstoreid ,sstorename ,sum(ssnetprofit) as storesalesprofit ,sum(srnetloss) as storereturnsloss ,sum(csnetprofit) as catalogsalesprofit from store_sales ,store_returns ,catalog_sales ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,item where d1.d_moy = 4 and d1.d_year = 2001 and d1.ddatesk = sssolddate_sk and iitemsk = ssitemsk and sstoresk = ssstoresk and sscustomersk = srcustomersk and ssitemsk = sritemsk and ssticketnumber = srticketnumber and srreturneddatesk = d2.ddate_sk and d2.d_moy between 4 and 10 and d2.d_year = 2001 and srcustomersk = csbillcustomer_sk and sritemsk = csitemsk and cssolddatesk = d3.ddate_sk and d3.d_moy between 4 and 10 and

= 2001 group by iitemid ,iitemdesc ,sstoreid ,sstorename order by iitemid ,iitemdesc ,sstoreid ,sstorename limit 100; -- query 26 select iitemid, avg(cs_quantity) agg1, avg(cslistprice) agg2, avg(cscouponamt) agg3, avg(cssalesprice) agg4 from catalogsales, customerdemographics, date_dim, item, promotion where cssolddatesk = ddate_sk and csitemsk = iitemsk and csbillcdemosk = cddemo_sk and cspromosk = ppromosk and cd_gender = 'M' and cdmaritalstatus = 'S' and cdeducationstatus = 'College' and (pchannelemail = 'N' or pchannelevent = 'N') and d_year = 2000 group by iitemid order by iitemid limit 100; -- query 27 select iitemid, sstate, grouping(sstate) g_state, avg(ss_quantity) agg1, avg(sslistprice) agg2, avg(sscouponamt) agg3, avg(sssalesprice) agg4 from storesales, customerdemographics, date_dim, store, item where sssolddatesk = ddate_sk and ssitemsk = iitemsk and ssstoresk = sstoresk and sscdemosk = cddemosk and cd_gender = 'M' and cdmaritalstatus = 'S' and cdeducationstatus = 'College' and d_year = 2002 and s_state in ('TN','TN', 'TN', 'TN', 'TN', 'TN') group by rollup (iitemid, s_state) order by iitemid ,s_state limit 100; -- query 28 select * from (select avg(sslistprice) B1_LP ,count(sslistprice) B1_CNT ,count(distinct sslistprice) B1_CNTD from store_sales where ss_quantity between 0 and 5 and (sslistprice between 8 and 8+10 or sscouponamt between 459 and 459+1000 or sswholesalecost between 57 and 57+20)) B1, (select avg(sslistprice) B2_LP ,count(sslistprice) B2_CNT ,count(distinct sslistprice) B2_CNTD from store_sales where ss_quantity between 6 and 10 and (sslistprice between 90 and 90+10 or sscouponamt between 2323 and 2323+1000 or sswholesalecost between 31 and 31+20)) B2, (select avg(sslistprice) B3_LP ,count(sslistprice) B3_CNT ,count(distinct sslistprice) B3_CNTD from store_sales where ss_quantity between 11 and 15 and (sslistprice between 142 and 142+10 or sscouponamt between 12214 and 12214+1000 or sswholesalecost between 79 and 79+20)) B3, (select avg(sslistprice) B4_LP ,count(sslistprice) B4_CNT ,count(distinct sslistprice) B4_CNTD from store_sales where ss_quantity between 16 and 20 and (sslistprice between 135 and 135+10 or sscouponamt between 6071 and 6071+1000 or sswholesalecost between 38 and 38+20)) B4, (select avg(sslistprice) B5_LP ,count(sslistprice) B5_CNT ,count(distinct sslistprice) B5_CNTD from store_sales where ss_quantity between 21 and 25 and (sslistprice between 122 and 122+10 or sscouponamt between 836 and 836+1000 or sswholesalecost between 17 and 17+20)) B5, (select avg(sslistprice) B6_LP ,count(sslistprice) B6_CNT ,count(distinct sslistprice) B6_CNTD from store_sales where ss_quantity between 26 and 30 and (sslistprice between 154 and 154+10 or sscouponamt between 7326 and 7326+1000 or sswholesalecost between 7 and 7+20)) B6 limit 100; -- query 29 select iitemid ,iitemdesc ,sstoreid ,sstorename ,sum(ssquantity) as storesales_quantity ,sum(srreturnquantity) as storereturnsquantity ,sum(csquantity) as catalogsales_quantity from store_sales ,store_returns ,catalog_sales ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,item where d1.d_moy = 9 and d1.d_year = 1999 and d1.ddatesk = sssolddate_sk and iitemsk = ssitemsk and sstoresk = ssstoresk and sscustomersk = srcustomersk and ssitemsk = sritemsk and ssticketnumber = srticketnumber and srreturneddatesk = d2.ddate_sk and d2.d_moy between 9 and 9 + 3 and d2.d_year = 1999 and srcustomersk = csbillcustomer_sk and sritemsk = csitemsk and cssolddatesk = d3.ddate_sk and d3.d_year in (1999,1999+1,1999+2) group by iitemid ,iitemdesc ,sstoreid ,sstorename order by iitemid ,iitemdesc ,sstoreid ,sstorename limit 100; -- query 30 with customertotalreturn as (select wrreturningcustomersk as ctrcustomer_sk ,castate as ctrstate, sum(wrreturnamt) as ctrtotalreturn from web_returns ,date_dim ,customer_address where wrreturneddatesk = ddate_sk and d_year =2002 and wrreturningaddrsk = caaddress_sk group by wrreturningcustomer_sk ,ca_state) select ccustomerid,csalutation,cfirstname,clastname,cpreferredcustflag ,cbirthday,cbirthmonth,cbirthyear,cbirthcountry,clogin,cemail_address ,clastreviewdate,ctrtotal_return from customertotalreturn ctr1 ,customer_address ,customer where ctr1.ctrtotalreturn > (select avg(ctrtotalreturn)*1.2 from customertotalreturn ctr2 where ctr1.ctrstate = ctr2.ctrstate) and caaddresssk = ccurrentaddr_sk and ca_state = 'GA' and ctr1.ctrcustomersk = ccustomersk order by ccustomerid,csalutation,cfirstname,clastname,cpreferredcustflag ,cbirthday,cbirthmonth,cbirthyear,cbirthcountry,clogin,cemail_address ,clastreviewdate,ctrtotal_return limit 100; -- query 31 with ss as (select cacounty,dqoy, dyear,sum(ssextsalesprice) as store_sales from storesales,datedim,customer_address where sssolddatesk = ddate_sk and ssaddrsk=caaddresssk group by cacounty,dqoy, d_year), ws as (select cacounty,dqoy, dyear,sum(wsextsalesprice) as web_sales from websales,datedim,customer_address where wssolddatesk = ddate_sk and wsbilladdrsk=caaddress_sk group by cacounty,dqoy, d_year) select ss1.ca_county ,ss1.d_year ,ws2.websales/ws1.websales webq1q2_increase ,ss2.storesales/ss1.storesales storeq1q2_increase ,ws3.websales/ws2.websales webq2q3_increase ,ss3.storesales/ss2.storesales storeq2q3_increase from ss ss1 ,ss ss2 ,ss ss3 ,ws ws1 ,ws ws2 ,ws ws3 where ss1.d_qoy = 1 and ss1.d_year = 2000 and ss1.cacounty = ss2.cacounty and ss2.d_qoy = 2 and ss2.d_year = 2000 and ss2.cacounty = ss3.cacounty and ss3.d_qoy = 3 and ss3.d_year = 2000 and ss1.cacounty = ws1.cacounty and ws1.d_qoy = 1 and ws1.d_year = 2000 and ws1.cacounty = ws2.cacounty and

= 2 and ws2.d_year = 2000 and ws1.cacounty = ws3.cacounty and ws3.d_qoy = 3 and ws3.d_year =2000 and case when ws1.websales > 0 then ws2.websales/ws1.web_sales else null end > case when ss1.storesales > 0 then ss2.storesales/ss1.store_sales else null end and case when ws2.websales > 0 then ws3.websales/ws2.web_sales else null end > case when ss2.storesales > 0 then ss3.storesales/ss2.store_sales else null end order by ss1.ca_county; -- query 32 select sum(csextdiscount_amt) as "excess discount amount" from catalog_sales ,item ,date_dim where imanufactid = 977 and iitemsk = csitemsk and d_date between '2000-01-27' and date_add(cast('2000-01-27' as date), 90) and ddatesk = cssolddate_sk and csextdiscount_amt > ( select 1.3 * avg(csextdiscount_amt) from catalog_sales ,date_dim where csitemsk = iitemsk and d_date between '2000-01-27' and date_add(cast('2000-01-27' as date), 90) and ddatesk = cssolddate_sk ) limit 100; -- query 33 with ss as ( select imanufactid,sum(ssextsalesprice) totalsales from store_sales, date_dim, customer_address, item where imanufactid in (select imanufactid from item where i_category in ('Electronics')) and ssitemsk = iitemsk and sssolddatesk = ddate_sk and d_year = 1998 and d_moy = 5 and ssaddrsk = caaddresssk and cagmtoffset = -5 group by imanufactid), cs as ( select imanufactid,sum(csextsalesprice) totalsales from catalog_sales, date_dim, customer_address, item where imanufactid in (select imanufactid from item where i_category in ('Electronics')) and csitemsk = iitemsk and cssolddatesk = ddate_sk and d_year = 1998 and d_moy = 5 and csbilladdrsk = caaddress_sk and cagmtoffset = -5 group by imanufactid), ws as ( select imanufactid,sum(wsextsalesprice) totalsales from web_sales, date_dim, customer_address, item where imanufactid in (select imanufactid from item where i_category in ('Electronics')) and wsitemsk = iitemsk and wssolddatesk = ddate_sk and d_year = 1998 and d_moy = 5 and wsbilladdrsk = caaddress_sk and cagmtoffset = -5 group by imanufactid) select imanufactid ,sum(totalsales) totalsales from (select * from ss union all select * from cs union all select * from ws) tmp1 group by imanufactid order by total_sales limit 100; -- query 34 select clastname ,cfirstname ,c_salutation ,cpreferredcust_flag ,ssticketnumber ,cnt from (select ssticketnumber ,sscustomersk ,count(*) cnt from storesales,datedim,store,household_demographics where storesales.sssolddatesk = datedim.ddate_sk and storesales.ssstoresk = store.sstore_sk and storesales.sshdemosk = householddemographics.hddemosk and (datedim.ddom between 1 and 3 or datedim.ddom between 25 and 28) and (householddemographics.hdbuy_potential = '>10000' or householddemographics.hdbuy_potential = 'Unknown') and householddemographics.hdvehicle_count > 0 and (case when householddemographics.hdvehicle_count > 0 then householddemographics.hddepcount/ householddemographics.hdvehiclecount else null end) > 1.2 and datedim.dyear in (1999,1999+1,1999+2) and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County', 'Williamson County','Williamson County','Williamson County','Williamson County') group by ssticketnumber,sscustomersk) dn,customer where sscustomersk = ccustomersk and cnt between 15 and 20 order by clastname,cfirstname,csalutation,cpreferredcustflag desc, ssticketnumber; -- query 35 select ca_state, cd_gender, cdmaritalstatus, cddepcount, count(*) cnt1, min(cddepcount), max(cddepcount), avg(cddepcount), cddepemployed_count, count(*) cnt2, min(cddepemployed_count), max(cddepemployed_count), avg(cddepemployed_count), cddepcollege_count, count(*) cnt3, min(cddepcollege_count), max(cddepcollege_count), avg(cddepcollege_count) from customer c,customeraddress ca,customerdemographics where c.ccurrentaddrsk = ca.caaddress_sk and cddemosk = c.ccurrentcdemo_sk and exists (select * from storesales,datedim where c.ccustomersk = sscustomersk and sssolddatesk = ddate_sk and d_year = 2002 and d_qoy < 4) and exists (select * from (select wsbillcustomer_sk customsk from websales,datedim where wssolddatesk = ddate_sk and d_year = 2002 and d_qoy < 4 union all select csshipcustomer_sk customsk from catalogsales,datedim where cssolddatesk = ddate_sk and d_year = 2002 and d_qoy < 4)x where x.customsk = c.ccustomersk) group by ca_state, cd_gender, cdmaritalstatus, cddepcount, cddepemployed_count, cddepcollege_count order by ca_state, cd_gender, cdmaritalstatus, cddepcount, cddepemployed_count, cddepcollege_count limit 100; -- query 36 select sum(ssnetprofit)/sum(ssextsalesprice) as grossmargin ,i_category ,i_class ,grouping(icategory)+grouping(iclass) as lochierarchy ,rank() over ( partition by grouping(icategory)+grouping(iclass), case when grouping(iclass) = 0 then icategory end order by sum(ssnetprofit)/sum(ssextsalesprice) asc) as rankwithin_parent from store_sales ,date_dim d1 ,item ,store where d1.d_year = 2001 and

= sssolddate_sk and iitemsk = ssitemsk and sstoresk = ssstoresk and s_state in ('TN','TN','TN','TN', 'TN','TN','TN','TN') group by rollup(icategory,iclass) order by lochierarchy desc ,case when lochierarchy = 0 then i_category end ,rankwithinparent limit 100; -- query 37 select iitemid ,iitemdesc ,icurrentprice from item, inventory, datedim, catalogsales where icurrentprice between 68 and 68 + 30 and invitemsk = iitemsk and ddatesk=invdatesk and ddate between cast('2000-02-01' as date) and dateadd(cast('2000-02-01' as date), 60) and imanufactid in (677,940,694,808) and invquantityon_hand between 100 and 500 and csitemsk = iitemsk group by iitemid,iitemdesc,icurrentprice order by iitemid limit 100; -- query 38 select count(*) from ( select distinct clastname, cfirstname, d_date from storesales, datedim, customer where storesales.sssolddatesk = datedim.ddate_sk and storesales.sscustomersk = customer.ccustomer_sk and dmonthseq between 1200 and 1200 + 11 intersect select distinct clastname, cfirstname, d_date from catalogsales, datedim, customer where catalogsales.cssolddatesk = datedim.ddate_sk and catalogsales.csbillcustomersk = customer.ccustomersk and dmonthseq between 1200 and 1200 + 11 intersect select distinct clastname, cfirstname, d_date from websales, datedim, customer where websales.wssolddatesk = datedim.ddate_sk and websales.wsbillcustomersk = customer.ccustomersk and dmonthseq between 1200 and 1200 + 11 ) hot_cust limit 100; -- query 39 with inv as (select wwarehousename,wwarehousesk,iitemsk,d_moy ,stdev,mean, case mean when 0 then null else stdev/mean end cov from(select wwarehousename,wwarehousesk,iitemsk,d_moy ,stddevsamp(invquantityonhand) stdev,avg(invquantityon_hand) mean from inventory ,item ,warehouse ,date_dim where invitemsk = iitemsk and invwarehousesk = wwarehousesk and invdatesk = ddatesk and d_year =2001 group by wwarehousename,wwarehousesk,iitemsk,d_moy) foo where case mean when 0 then 0 else stdev/mean end > 1) select inv1.wwarehousesk,inv1.iitemsk,inv1.d_moy,inv1.mean, inv1.cov ,inv2.wwarehousesk,inv2.iitemsk,inv2.d_moy,inv2.mean, inv2.cov from inv inv1,inv inv2 where inv1.iitemsk = inv2.iitemsk and inv1.wwarehousesk = inv2.wwarehousesk and inv1.d_moy=1 and inv2.d_moy=1+1 order by inv1.wwarehousesk,inv1.iitemsk,inv1.d_moy,inv1.mean,inv1.cov ,inv2.d_moy,inv2.mean, inv2.cov ; with inv as (select wwarehousename,wwarehousesk,iitemsk,d_moy ,stdev,mean, case mean when 0 then null else stdev/mean end cov from(select wwarehousename,wwarehousesk,iitemsk,d_moy ,stddevsamp(invquantityonhand) stdev,avg(invquantityon_hand) mean from inventory ,item ,warehouse ,date_dim where invitemsk = iitemsk and invwarehousesk = wwarehousesk and invdatesk = ddatesk and d_year =2001 group by wwarehousename,wwarehousesk,iitemsk,d_moy) foo where case mean when 0 then 0 else stdev/mean end > 1) select inv1.wwarehousesk,inv1.iitemsk,inv1.d_moy,inv1.mean, inv1.cov ,inv2.wwarehousesk,inv2.iitemsk,inv2.d_moy,inv2.mean, inv2.cov from inv inv1,inv inv2 where inv1.iitemsk = inv2.iitemsk and inv1.wwarehousesk = inv2.wwarehousesk and inv1.d_moy=1 and inv2.d_moy=1+1 and inv1.cov > 1.5 order by inv1.wwarehousesk,inv1.iitemsk,inv1.d_moy,inv1.mean,inv1.cov ,inv2.d_moy,inv2.mean, inv2.cov ; -- query 40 select w_state ,iitemid ,sum(case when (cast(d_date as date) < cast ('2000-03-11' as date)) then cssalesprice - coalesce(crrefundedcash,0) else 0 end) as sales_before ,sum(case when (cast(d_date as date) >= cast ('2000-03-11' as date)) then cssalesprice - coalesce(crrefundedcash,0) else 0 end) as sales_after from catalogsales left outer join catalogreturns on (csordernumber = crordernumber and csitemsk = critemsk) ,warehouse ,item ,date_dim where icurrentprice between 0.99 and 1.49 and iitemsk = csitemsk and cswarehousesk = wwarehousesk and cssolddatesk = ddate_sk and ddate between dateadd(cast ('2000-03-11' as date), -30) and date_add(cast ('2000-03-11' as date), 30) group by wstate,iitem_id order by wstate,iitem_id limit 100; -- query 41 select distinct(iproductname) from item i1 where imanufactid between 738 and 738+40 and (select count(*) as item_cnt from item where (imanufact =

and ((i_category = 'Women' and (icolor = 'powder' or icolor = 'khaki') and (iunits = 'Ounce' or iunits = 'Oz') and (isize = 'medium' or isize = 'extra large') ) or (i_category = 'Women' and (icolor = 'brown' or icolor = 'honeydew') and (iunits = 'Bunch' or iunits = 'Ton') and (isize = 'N/A' or isize = 'small') ) or (i_category = 'Men' and (icolor = 'floral' or icolor = 'deep') and (iunits = 'N/A' or iunits = 'Dozen') and (isize = 'petite' or isize = 'large') ) or (i_category = 'Men' and (icolor = 'light' or icolor = 'cornflower') and (iunits = 'Box' or iunits = 'Pound') and (isize = 'medium' or isize = 'extra large') ))) or (imanufact = i1.imanufact and ((i_category = 'Women' and (icolor = 'midnight' or icolor = 'snow') and (iunits = 'Pallet' or iunits = 'Gross') and (isize = 'medium' or isize = 'extra large') ) or (i_category = 'Women' and (icolor = 'cyan' or icolor = 'papaya') and (iunits = 'Cup' or iunits = 'Dram') and (isize = 'N/A' or isize = 'small') ) or (i_category = 'Men' and (icolor = 'orange' or icolor = 'frosted') and (iunits = 'Each' or iunits = 'Tbl') and (isize = 'petite' or isize = 'large') ) or (i_category = 'Men' and (icolor = 'forest' or icolor = 'ghost') and (iunits = 'Lb' or iunits = 'Bundle') and (isize = 'medium' or isize = 'extra large') )))) > 0 order by iproductname limit 100; -- query 42 select dt.d_year ,item.icategoryid ,item.i_category ,sum(ssextsales_price) from date_dim dt ,store_sales ,item where dt.ddatesk = storesales.sssolddatesk and storesales.ssitemsk = item.iitem_sk and item.imanagerid = 1 and dt.d_moy=11 and dt.d_year=2000 group by dt.d_year ,item.icategoryid ,item.i_category order by sum(ssextsalesprice) desc,dt.dyear ,item.icategoryid ,item.i_category limit 100 ; -- query 43 select sstorename, sstoreid, sum(case when (ddayname='Sunday') then sssalesprice else null end) sun_sales, sum(case when (ddayname='Monday') then sssalesprice else null end) mon_sales, sum(case when (ddayname='Tuesday') then sssalesprice else null end) tue_sales, sum(case when (ddayname='Wednesday') then sssalesprice else null end) wed_sales, sum(case when (ddayname='Thursday') then sssalesprice else null end) thu_sales, sum(case when (ddayname='Friday') then sssalesprice else null end) fri_sales, sum(case when (ddayname='Saturday') then sssalesprice else null end) sat_sales from datedim, storesales, store where ddatesk = sssolddate_sk and sstoresk = ssstoresk and sgmtoffset = -5 and d_year = 2000 group by sstorename, sstoreid order by sstorename, sstoreid,sunsales,monsales,tuesales,wedsales,thusales,frisales,sat_sales limit 100; -- query 44 select asceding.rnk, i1.iproductname bestperforming, i2.iproductname worstperforming from(select * from (select itemsk,rank() over (order by rankcol asc) rnk from (select ssitemsk itemsk,avg(ssnetprofit) rankcol from store_sales ss1 where ssstoresk = 4 group by ssitemsk having avg(ssnetprofit) > 0.9*(select avg(ssnetprofit) rank_col from store_sales where ssstoresk = 4 and ssaddrsk is null group by ssstoresk))V1)V11 where rnk < 11) asceding, (select * from (select itemsk,rank() over (order by rankcol desc) rnk from (select ssitemsk itemsk,avg(ssnetprofit) rankcol from store_sales ss1 where ssstoresk = 4 group by ssitemsk having avg(ssnetprofit) > 0.9*(select avg(ssnetprofit) rank_col from store_sales where ssstoresk = 4 and ssaddrsk is null group by ssstoresk))V2)V21 where rnk < 11) descending, item i1, item i2 where asceding.rnk = descending.rnk and i1.iitemsk=asceding.item_sk and i2.iitemsk=descending.item_sk order by asceding.rnk limit 100; -- query 45 select cazip, cacity, sum(wssalesprice) from websales, customer, customeraddress, date_dim, item where wsbillcustomersk = ccustomer_sk and ccurrentaddrsk = caaddress_sk and wsitemsk = iitemsk and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') or iitemid in (select iitemid from item where iitemsk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) ) ) and wssolddatesk = ddate_sk and dqoy = 2 and dyear = 2001 group by cazip, cacity order by cazip, cacity limit 100; -- query 46 select clastname ,cfirstname ,ca_city ,bought_city ,ssticketnumber ,amt,profit from (select ssticketnumber ,sscustomersk ,cacity boughtcity ,sum(sscouponamt) amt ,sum(ssnetprofit) profit from storesales,datedim,store,householddemographics,customeraddress where storesales.sssolddatesk = datedim.ddate_sk and storesales.ssstoresk = store.sstore_sk and storesales.sshdemosk = householddemographics.hddemosk and storesales.ssaddrsk = customeraddress.caaddresssk and (householddemographics.hddep_count = 4 or householddemographics.hdvehicle_count= 3) and datedim.ddow in (6,0) and datedim.dyear in (1999,1999+1,1999+2) and store.s_city in ('Fairview','Midway','Fairview','Fairview','Fairview') group by ssticketnumber,sscustomersk,ssaddrsk,cacity) dn,customer,customeraddress current_addr where sscustomersk = ccustomersk and customer.ccurrentaddrsk = currentaddr.caaddresssk and

<> bought_city order by clastname ,cfirstname ,ca_city ,bought_city ,ssticketnumber limit 100; -- query 47 with v1 as( select icategory, ibrand, sstorename, scompanyname, dyear, dmoy, sum(sssalesprice) sum_sales, avg(sum(sssalesprice)) over (partition by icategory, ibrand, sstorename, scompanyname, d_year) avgmonthlysales, rank() over (partition by icategory, ibrand, sstorename, scompanyname order by dyear, dmoy) rn from item, storesales, datedim, store where ssitemsk = iitemsk and sssolddatesk = ddate_sk and ssstoresk = sstoresk and ( d_year = 1999 or ( dyear = 1999-1 and dmoy =12) or ( dyear = 1999+1 and dmoy =1) ) group by icategory, ibrand, sstorename, scompanyname, dyear, dmoy), v2 as( select v1.icategory, v1.ibrand, v1.sstorename, v1.scompanyname ,v1.dyear, v1.dmoy ,v1.avgmonthlysales ,v1.sumsales, v1lag.sumsales psum, v1lead.sum_sales nsum from v1, v1 v1lag, v1 v1lead where v1.icategory = v1lag.i_category and v1.icategory = v1lead.i_category and v1.ibrand = v1lag.i_brand and v1.ibrand = v1lead.i_brand and v1.sstorename = v1lag.sstore_name and v1.sstorename = v1lead.sstore_name and v1.scompanyname = v1lag.scompany_name and v1.scompanyname = v1lead.scompany_name and v1.rn = v1_lag.rn + 1 and v1.rn = v1_lead.rn - 1) select * from v2 where d_year = 1999 and avgmonthlysales > 0 and case when avgmonthlysales > 0 then abs(sumsales - avgmonthlysales) / avgmonthly_sales else null end > 0.1 order by sumsales - avgmonthlysales, sstore_name limit 100; -- query 48 select sum (ss_quantity) from storesales, store, customerdemographics, customeraddress, datedim where sstoresk = ssstoresk and sssolddatesk = ddatesk and dyear = 2000 and ( ( cddemosk = sscdemosk and cdmaritalstatus = 'M' and cdeducationstatus = '4 yr Degree' and sssalesprice between 100.00 and 150.00 ) or ( cddemosk = sscdemosk and cdmaritalstatus = 'D' and cdeducationstatus = '2 yr Degree' and sssalesprice between 50.00 and 100.00 ) or ( cddemosk = sscdemosk and cdmaritalstatus = 'S' and cdeducationstatus = 'College' and sssalesprice between 150.00 and 200.00 ) ) and ( ( ssaddrsk = caaddresssk and ca_country = 'United States' and ca_state in ('CO', 'OH', 'TX') and ssnetprofit between 0 and 2000 ) or (ssaddrsk = caaddresssk and ca_country = 'United States' and ca_state in ('OR', 'MN', 'KY') and ssnetprofit between 150 and 3000 ) or (ssaddrsk = caaddresssk and ca_country = 'United States' and ca_state in ('VA', 'CA', 'MS') and ssnetprofit between 50 and 25000 ) ) ; -- query 49 select channel, item, returnratio, returnrank, currency_rank from (select 'web' as channel ,web.item ,web.return_ratio ,web.return_rank ,web.currency_rank from ( select item ,return_ratio ,currency_ratio ,rank() over (order by returnratio) as returnrank ,rank() over (order by currencyratio) as currencyrank from ( select ws.wsitemsk as item ,(cast(sum(coalesce(wr.wrreturnquantity,0)) as decimal(15,4))/ cast(sum(coalesce(ws.wsquantity,0)) as decimal(15,4) )) as returnratio ,(cast(sum(coalesce(wr.wrreturnamt,0)) as decimal(15,4))/ cast(sum(coalesce(ws.wsnetpaid,0)) as decimal(15,4) )) as currency_ratio from websales ws left outer join webreturns wr on (ws.wsordernumber = wr.wrordernumber and ws.wsitemsk = wr.writemsk) ,date_dim where wr.wrreturnamt > 10000 and ws.wsnetprofit > 1 and ws.wsnetpaid > 0 and ws.ws_quantity > 0 and wssolddatesk = ddate_sk and d_year = 2001 and d_moy = 12 group by ws.wsitemsk ) in_web ) web where ( web.return_rank <= 10 or web.currency_rank <= 10 ) union select 'catalog' as channel ,catalog.item ,catalog.return_ratio ,catalog.return_rank ,catalog.currency_rank from ( select item ,return_ratio ,currency_ratio ,rank() over (order by returnratio) as returnrank ,rank() over (order by currencyratio) as currencyrank from ( select cs.csitemsk as item ,(cast(sum(coalesce(cr.crreturnquantity,0)) as decimal(15,4))/ cast(sum(coalesce(cs.csquantity,0)) as decimal(15,4) )) as returnratio ,(cast(sum(coalesce(cr.crreturnamount,0)) as decimal(15,4))/ cast(sum(coalesce(cs.csnetpaid,0)) as decimal(15,4) )) as currency_ratio from catalogsales cs left outer join catalogreturns cr on (cs.csordernumber = cr.crordernumber and cs.csitemsk = cr.critemsk) ,date_dim where cr.crreturnamount > 10000 and cs.csnetprofit > 1 and cs.csnetpaid > 0 and cs.cs_quantity > 0 and cssolddatesk = ddate_sk and d_year = 2001 and d_moy = 12 group by cs.csitemsk ) in_cat ) catalog where ( catalog.return_rank <= 10 or catalog.currency_rank <=10 ) union select 'store' as channel ,store.item ,store.return_ratio ,store.return_rank

from ( select item ,return_ratio ,currency_ratio ,rank() over (order by returnratio) as returnrank ,rank() over (order by currencyratio) as currencyrank from ( select sts.ssitemsk as item ,(cast(sum(coalesce(sr.srreturnquantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ssquantity,0)) as decimal(15,4) )) as returnratio ,(cast(sum(coalesce(sr.srreturnamt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ssnetpaid,0)) as decimal(15,4) )) as currency_ratio from storesales sts left outer join storereturns sr on (sts.ssticketnumber = sr.srticketnumber and sts.ssitemsk = sr.sritemsk) ,date_dim where sr.srreturnamt > 10000 and sts.ssnetprofit > 1 and sts.ssnetpaid > 0 and sts.ss_quantity > 0 and sssolddatesk = ddate_sk and d_year = 2001 and d_moy = 12 group by sts.ssitemsk ) in_store ) store where ( store.return_rank <= 10 or store.currency_rank <= 10 ) ) t1 order by 1,4,5,2 limit 100; -- query 50 select sstorename ,scompanyid ,sstreetnumber ,sstreetname ,sstreettype ,ssuitenumber ,s_city ,s_county ,s_state ,s_zip ,sum(case when (srreturneddatesk - sssolddatesk <= 30 ) then 1 else 0 end) as "30 days" ,sum(case when (srreturneddatesk - sssolddatesk > 30) and (srreturneddatesk - sssolddatesk <= 60) then 1 else 0 end ) as "31-60 days" ,sum(case when (srreturneddatesk - sssolddatesk > 60) and (srreturneddatesk - sssolddatesk <= 90) then 1 else 0 end) as "61-90 days" ,sum(case when (srreturneddatesk - sssolddatesk > 90) and (srreturneddatesk - sssolddatesk <= 120) then 1 else 0 end) as "91-120 days" ,sum(case when (srreturneddatesk - sssolddatesk > 120) then 1 else 0 end) as ">120 days" from store_sales ,store_returns ,store ,date_dim d1 ,date_dim d2 where d2.d_year = 2001 and d2.d_moy = 8 and ssticketnumber = srticketnumber and ssitemsk = sritemsk and sssolddatesk = d1.ddate_sk and srreturneddatesk = d2.ddate_sk and sscustomersk = srcustomersk and ssstoresk = sstoresk group by sstorename ,scompanyid ,sstreetnumber ,sstreetname ,sstreettype ,ssuitenumber ,s_city ,s_county ,s_state ,s_zip order by sstorename ,scompanyid ,sstreetnumber ,sstreetname ,sstreettype ,ssuitenumber ,s_city ,s_county ,s_state ,s_zip limit 100; -- query 51 WITH web_v1 as ( select wsitemsk itemsk, ddate, sum(sum(wssalesprice)) over (partition by wsitemsk order by ddate rows between unbounded preceding and current row) cumesales from web_sales ,date_dim where wssolddatesk=ddate_sk and dmonthseq between 1200 and 1200+11 and wsitemsk is not NULL group by wsitemsk, d_date), store_v1 as ( select ssitemsk itemsk, ddate, sum(sum(sssalesprice)) over (partition by ssitemsk order by ddate rows between unbounded preceding and current row) cumesales from store_sales ,date_dim where sssolddatesk=ddate_sk and dmonthseq between 1200 and 1200+11 and ssitemsk is not NULL group by ssitemsk, d_date) select * from (select item_sk ,d_date ,web_sales ,store_sales ,max(web_sales) over (partition by itemsk order by ddate rows between unbounded preceding and current row) web_cumulative ,max(store_sales) over (partition by itemsk order by ddate rows between unbounded preceding and current row) store_cumulative from (select case when web.itemsk is not null then web.itemsk else store.itemsk end itemsk ,case when web.ddate is not null then web.ddate else store.ddate end ddate ,web.cumesales websales ,store.cumesales storesales from webv1 web full outer join storev1 store on (web.itemsk = store.itemsk and web.ddate = store.ddate) )x )y where webcumulative > storecumulative order by item_sk ,d_date limit 100; -- query 52 select dt.d_year ,item.ibrandid brand_id ,item.i_brand brand ,sum(ssextsalesprice) extprice from date_dim dt ,store_sales ,item where dt.ddatesk = storesales.sssolddatesk and storesales.ssitemsk = item.iitem_sk and item.imanagerid = 1 and dt.d_moy=11 and dt.d_year=2000 group by dt.d_year ,item.i_brand ,item.ibrandid order by dt.d_year ,ext_price desc ,brand_id limit 100 ; -- query 53 select * from (select imanufactid, sum(sssalesprice) sum_sales, avg(sum(sssalesprice)) over (partition by imanufactid) avgquarterlysales from item, storesales, datedim, store where ssitemsk = iitemsk and sssolddatesk = ddate_sk and ssstoresk = sstoresk and dmonthseq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) and ((i_category in ('Books','Children','Electronics') and i_class in ('personal','portable','reference','self-help') and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', 'exportiunivamalg #9','scholaramalgamalg #9')) or(i_category in ('Women','Music','Men') and i_class in ('accessories','classical','fragrances','pants') and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1',

#1'))) group by imanufactid, d_qoy ) tmp1 where case when avgquarterlysales > 0 then abs (sumsales - avgquarterlysales)/ avgquarterly_sales else null end > 0.1 order by avgquarterlysales, sum_sales, imanufactid limit 100; -- query 54 with my_customers as ( select distinct ccustomersk , ccurrentaddr_sk from ( select cssolddatesk solddate_sk, csbillcustomersk customersk, csitemsk item_sk from catalog_sales union all select wssolddatesk solddate_sk, wsbillcustomersk customersk, wsitemsk item_sk from web_sales ) csorws_sales, item, date_dim, customer where solddatesk = ddatesk and itemsk = iitem_sk and i_category = 'Women' and i_class = 'maternity' and ccustomersk = csorwssales.customersk and d_moy = 12 and d_year = 1998 ) , my_revenue as ( select ccustomersk, sum(ssextsales_price) as revenue from my_customers, store_sales, customer_address, store, date_dim where ccurrentaddrsk = caaddress_sk and cacounty = scounty and castate = sstate and sssolddatesk = ddate_sk and ccustomersk = sscustomersk and dmonthseq between (select distinct dmonthseq+1 from datedim where dyear = 1998 and d_moy = 12) and (select distinct dmonthseq+3 from datedim where dyear = 1998 and d_moy = 12) group by ccustomersk ) , segments as (select cast((revenue/50) as int) as segment from my_revenue ) select segment, count() as num_customers, segment50 as segment_base from segments group by segment order by segment, num_customers limit 100; -- query 55 select ibrandid brandid, ibrand brand, sum(ssextsalesprice) extprice from datedim, storesales, item where ddatesk = sssolddate_sk and ssitemsk = iitemsk and imanagerid=28 and d_moy=11 and d_year=1999 group by ibrand, ibrand_id order by extprice desc, ibrand_id limit 100 ; -- query 56 with ss as ( select iitemid,sum(ssextsalesprice) totalsales from store_sales, date_dim, customer_address, item where iitemid in (select iitemid from item where i_color in ('slate', 'blanched', 'burnished')) and ssitemsk = iitemsk and sssolddatesk = ddate_sk and d_year = 2001 and d_moy = 2 and ssaddrsk = caaddresssk and cagmtoffset = -5 group by iitemid), cs as ( select iitemid,sum(csextsalesprice) totalsales from catalog_sales, date_dim, customer_address, item where iitemid in (select iitemid from item where i_color in ('slate', 'blanched', 'burnished')) and csitemsk = iitemsk and cssolddatesk = ddate_sk and d_year = 2001 and d_moy = 2 and csbilladdrsk = caaddress_sk and cagmtoffset = -5 group by iitemid), ws as ( select iitemid,sum(wsextsalesprice) totalsales from web_sales, date_dim, customer_address, item where iitemid in (select iitemid from item where i_color in ('slate', 'blanched', 'burnished')) and wsitemsk = iitemsk and wssolddatesk = ddate_sk and d_year = 2001 and d_moy = 2 and wsbilladdrsk = caaddress_sk and cagmtoffset = -5 group by iitemid) select iitemid ,sum(totalsales) totalsales from (select * from ss union all select * from cs union all select * from ws) tmp1 group by iitemid order by total_sales, iitemid limit 100; -- query 57 with v1 as( select icategory, ibrand, cc_name, dyear, dmoy, sum(cssalesprice) sum_sales, avg(sum(cssalesprice)) over (partition by icategory, ibrand, ccname, dyear) avgmonthlysales, rank() over (partition by icategory, ibrand, cc_name order by dyear, dmoy) rn from item, catalogsales, datedim, call_center where csitemsk = iitemsk and cssolddatesk = ddate_sk and cccallcentersk= cscallcentersk and ( d_year = 1999 or ( dyear = 1999-1 and dmoy =12) or ( dyear = 1999+1 and dmoy =1) ) group by icategory, ibrand, ccname , dyear, d_moy), v2 as( select v1.icategory, v1.ibrand, v1.cc_name ,v1.dyear, v1.dmoy ,v1.avgmonthlysales ,v1.sumsales, v1lag.sumsales psum, v1lead.sum_sales nsum from v1, v1 v1lag, v1 v1lead where v1.icategory = v1lag.i_category and v1.icategory = v1lead.i_category and v1.ibrand = v1lag.i_brand and v1.ibrand = v1lead.i_brand and v1. ccname = v1lag. cc_name and v1. ccname = v1lead. cc_name and v1.rn = v1_lag.rn + 1 and v1.rn =

- 1) select * from v2 where d_year = 1999 and avgmonthlysales > 0 and case when avgmonthlysales > 0 then abs(sumsales - avgmonthlysales) / avgmonthly_sales else null end > 0.1 order by sumsales - avgmonthlysales, ccname limit 100; -- query 58 with ss_items as (select iitemid item_id ,sum(ssextsalesprice) ssitem_rev from store_sales ,item ,date_dim where ssitemsk = iitemsk and ddate in (select ddate from date_dim where dweekseq = (select dweekseq from date_dim where d_date = '2000-01-03')) and sssolddatesk = ddate_sk group by iitemid), cs_items as (select iitemid item_id ,sum(csextsalesprice) csitem_rev from catalog_sales ,item ,date_dim where csitemsk = iitemsk and ddate in (select ddate from date_dim where dweekseq = (select dweekseq from date_dim where d_date = '2000-01-03')) and cssolddatesk = ddate_sk group by iitemid), ws_items as (select iitemid item_id ,sum(wsextsalesprice) wsitem_rev from web_sales ,item ,date_dim where wsitemsk = iitemsk and ddate in (select ddate from date_dim where dweekseq =(select dweekseq from date_dim where d_date = '2000-01-03')) and wssolddatesk = ddate_sk group by iitemid) select ssitems.itemid ,ssitemrev ,ssitemrev/((ssitemrev+csitemrev+wsitemrev)/3) * 100 ss_dev ,csitemrev ,csitemrev/((ssitemrev+csitemrev+wsitemrev)/3) * 100 cs_dev ,wsitemrev ,wsitemrev/((ssitemrev+csitemrev+wsitemrev)/3) * 100 ws_dev ,(ssitemrev+csitemrev+wsitemrev)/3 average from ssitems,csitems,ws_items where ssitems.itemid=csitems.itemid and ssitems.itemid=wsitems.itemid and ssitemrev between 0.9 cs_item_rev and 1.1 csitemrev and ssitemrev between 0.9 ws_item_rev and 1.1 wsitemrev and csitemrev between 0.9 ss_item_rev and 1.1 ssitemrev and csitemrev between 0.9 ws_item_rev and 1.1 wsitemrev and wsitemrev between 0.9 ss_item_rev and 1.1 ssitemrev and wsitemrev between 0.9 cs_item_rev and 1.1 csitemrev order by item_id ,ssitemrev limit 100; -- query 59 with wss as (select dweekseq, ssstoresk, sum(case when (ddayname='Sunday') then sssalesprice else null end) sun_sales, sum(case when (ddayname='Monday') then sssalesprice else null end) mon_sales, sum(case when (ddayname='Tuesday') then sssalesprice else null end) tue_sales, sum(case when (ddayname='Wednesday') then sssalesprice else null end) wed_sales, sum(case when (ddayname='Thursday') then sssalesprice else null end) thu_sales, sum(case when (ddayname='Friday') then sssalesprice else null end) fri_sales, sum(case when (ddayname='Saturday') then sssalesprice else null end) sat_sales from storesales,datedim where ddatesk = sssolddate_sk group by dweekseq,ssstoresk ) select sstorename1,sstoreid1,dweekseq1 ,sunsales1/sunsales2,monsales1/monsales2 ,tuesales1/tuesales2,wedsales1/wedsales2,thusales1/thusales2 ,frisales1/frisales2,satsales1/satsales2 from (select sstorename sstorename1,wss.dweekseq dweekseq1 ,sstoreid sstoreid1,sunsales sunsales1 ,monsales monsales1,tuesales tuesales1 ,wedsales wedsales1,thusales thusales1 ,frisales frisales1,satsales satsales1 from wss,store,date_dim d where d.dweekseq = wss.dweekseq and ssstoresk = sstoresk and dmonthseq between 1212 and 1212 + 11) y, (select sstorename sstorename2,wss.dweekseq dweekseq2 ,sstoreid sstoreid2,sunsales sunsales2 ,monsales monsales2,tuesales tuesales2 ,wedsales wedsales2,thusales thusales2 ,frisales frisales2,satsales satsales2 from wss,store,date_dim d where d.dweekseq =

and ssstoresk = sstoresk and dmonthseq between 1212+ 12 and 1212 + 23) x where sstoreid1=sstoreid2 and dweekseq1=dweekseq2-52 order by sstorename1,sstoreid1,dweekseq1 limit 100; -- query 60 with ss as ( select iitemid,sum(ssextsalesprice) totalsales from store_sales, date_dim, customer_address, item where iitemid in (select iitemid from item where i_category in ('Music')) and ssitemsk = iitemsk and sssolddatesk = ddate_sk and d_year = 1998 and d_moy = 9 and ssaddrsk = caaddresssk and cagmtoffset = -5 group by iitemid), cs as ( select iitemid,sum(csextsalesprice) totalsales from catalog_sales, date_dim, customer_address, item where iitemid in (select iitemid from item where i_category in ('Music')) and csitemsk = iitemsk and cssolddatesk = ddate_sk and d_year = 1998 and d_moy = 9 and csbilladdrsk = caaddress_sk and cagmtoffset = -5 group by iitemid), ws as ( select iitemid,sum(wsextsalesprice) totalsales from web_sales, date_dim, customer_address, item where iitemid in (select iitemid from item where i_category in ('Music')) and wsitemsk = iitemsk and wssolddatesk = ddate_sk and d_year = 1998 and d_moy = 9 and wsbilladdrsk = caaddress_sk and cagmtoffset = -5 group by iitemid) select iitemid ,sum(totalsales) totalsales from (select * from ss union all select * from cs union all select * from ws) tmp1 group by iitemid order by iitemid ,total_sales limit 100; -- query 61 select promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 from (select sum(ssextsales_price) promotions from store_sales ,store ,promotion ,date_dim ,customer ,customer_address ,item where sssolddatesk = ddate_sk and ssstoresk = sstoresk and sspromosk = ppromosk and sscustomersk= ccustomersk and caaddresssk = ccurrentaddr_sk and ssitemsk = iitemsk and cagmtoffset = -5 and i_category = 'Jewelry' and (pchanneldmail = 'Y' or pchannelemail = 'Y' or pchanneltv = 'Y') and sgmtoffset = -5 and d_year = 1998 and dmoy = 11) promotionalsales, (select sum(ssextsales_price) total from store_sales ,store ,date_dim ,customer ,customer_address ,item where sssolddatesk = ddate_sk and ssstoresk = sstoresk and sscustomersk= ccustomersk and caaddresssk = ccurrentaddr_sk and ssitemsk = iitemsk and cagmtoffset = -5 and i_category = 'Jewelry' and sgmtoffset = -5 and d_year = 1998 and dmoy = 11) allsales order by promotions, total limit 100; -- query 62 select substr(wwarehousename,1,20) ,sm_type ,web_name ,sum(case when (wsshipdatesk - wssolddatesk <= 30 ) then 1 else 0 end) as "30 days" ,sum(case when (wsshipdatesk - wssolddatesk > 30) and (wsshipdatesk - wssolddatesk <= 60) then 1 else 0 end ) as "31-60 days" ,sum(case when (wsshipdatesk - wssolddatesk > 60) and (wsshipdatesk - wssolddatesk <= 90) then 1 else 0 end) as "61-90 days" ,sum(case when (wsshipdatesk - wssolddatesk > 90) and (wsshipdatesk - wssolddatesk <= 120) then 1 else 0 end) as "91-120 days" ,sum(case when (wsshipdatesk - wssolddatesk > 120) then 1 else 0 end) as ">120 days" from web_sales ,warehouse ,ship_mode ,web_site ,date_dim where dmonthseq between 1200 and 1200 + 11 and wsshipdatesk = ddate_sk and wswarehousesk = wwarehousesk and wsshipmodesk = smshipmodesk and wswebsitesk = website_sk group by substr(wwarehousename,1,20) ,sm_type ,web_name order by substr(wwarehousename,1,20) ,sm_type ,web_name limit 100; -- query 63 select * from (select imanagerid ,sum(sssalesprice) sum_sales ,avg(sum(sssalesprice)) over (partition by imanagerid) avgmonthlysales from item ,store_sales ,date_dim ,store where ssitemsk = iitemsk and sssolddatesk = ddate_sk and ssstoresk = sstoresk and dmonthseq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) and (( i_category in ('Books','Children','Electronics') and i_class in ('personal','portable','reference','self-help') and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', 'exportiunivamalg #9','scholaramalgamalg #9')) or( i_category in ('Women','Music','Men') and i_class in ('accessories','classical','fragrances','pants') and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', 'importoamalg #1'))) group by imanagerid, d_moy) tmp1 where case when avgmonthlysales > 0 then abs (sumsales - avgmonthlysales) / avgmonthly_sales else null end > 0.1 order by imanagerid ,avgmonthlysales ,sum_sales limit 100; -- query 64 with cs_ui as (select csitemsk ,sum(csextlistprice) as sale,sum(crrefundedcash+crreversedcharge+crstore_credit) as refund from catalog_sales ,catalog_returns where csitemsk = critemsk and csordernumber = crordernumber group by csitemsk having sum(csextlistprice)>2*sum(crrefundedcash+crreversedcharge+crstore_credit)), cross_sales as (select iproductname product_name ,iitemsk item_sk ,sstorename store_name ,szip storezip ,ad1.castreetnumber bstreetnumber ,ad1.castreetname bstreetname ,ad1.cacity bcity ,ad1.cazip bzip ,ad2.castreetnumber cstreetnumber ,ad2.castreetname cstreetname ,ad2.cacity ccity ,ad2.cazip czip ,d1.d_year as syear ,d2.d_year as fsyear ,d3.d_year s2year ,count(*) cnt ,sum(sswholesalecost) s1 ,sum(sslistprice) s2 ,sum(sscouponamt) s3 FROM store_sales ,store_returns ,cs_ui ,date_dim d1 ,date_dim d2 ,date_dim d3 ,store ,customer ,customer_demographics cd1 ,customer_demographics cd2 ,promotion ,household_demographics hd1 ,household_demographics hd2 ,customer_address ad1 ,customer_address ad2 ,income_band ib1 ,income_band ib2 ,item WHERE ssstoresk = sstoresk AND sssolddatesk = d1.ddate_sk AND sscustomersk = ccustomersk AND sscdemosk= cd1.cddemosk AND sshdemosk = hd1.hddemosk AND ssaddrsk = ad1.caaddresssk and ssitemsk = iitemsk and ssitemsk = sritemsk and ssticketnumber = srticketnumber and ssitemsk = csui.csitem_sk and ccurrentcdemosk = cd2.cddemo_sk AND ccurrenthdemosk = hd2.hddemo_sk AND ccurrentaddrsk = ad2.caaddress_sk and cfirstsalesdatesk = d2.ddatesk and cfirstshiptodatesk = d3.ddatesk and sspromosk = ppromosk and hd1.hdincomebandsk = ib1.ibincomebandsk and hd2.hdincomebandsk = ib2.ibincomebandsk and cd1.cdmaritalstatus <> cd2.cdmaritalstatus and i_color in ('purple','burlywood','indian','spring','floral','medium') and icurrentprice between 64 and 64 + 10 and icurrentprice between 64 + 1 and 64 + 15 group by iproductname ,iitemsk ,sstorename ,s_zip ,ad1.castreetnumber ,ad1.castreetname ,ad1.ca_city ,ad1.ca_zip ,ad2.castreetnumber ,ad2.castreetname ,ad2.ca_city ,ad2.ca_zip ,d1.d_year ,d2.d_year ,d3.d_year ) select cs1.product_name ,cs1.store_name ,cs1.store_zip ,cs1.bstreetnumber ,cs1.bstreetname ,cs1.b_city ,cs1.b_zip ,cs1.cstreetnumber

,cs1.c_city ,cs1.c_zip ,cs1.syear ,cs1.cnt ,cs1.s1 as s11 ,cs1.s2 as s21 ,cs1.s3 as s31 ,cs2.s1 as s12 ,cs2.s2 as s22 ,cs2.s3 as s32 ,cs2.syear ,cs2.cnt from crosssales cs1,crosssales cs2 where cs1.itemsk=cs2.itemsk and cs1.syear = 1999 and cs2.syear = 1999 + 1 and cs2.cnt <= cs1.cnt and cs1.storename = cs2.storename and cs1.storezip = cs2.storezip order by cs1.product_name ,cs1.store_name ,cs2.cnt ,cs1.s1 ,cs2.s1; -- query 65 select sstorename, iitemdesc, sc.revenue, icurrentprice, iwholesalecost, i_brand from store, item, (select ssstoresk, avg(revenue) as ave from (select ssstoresk, ssitemsk, sum(sssalesprice) as revenue from storesales, datedim where sssolddatesk = ddatesk and dmonth_seq between 1176 and 1176+11 group by ssstoresk, ssitemsk) sa group by ssstoresk) sb, (select ssstoresk, ssitemsk, sum(sssalesprice) as revenue from storesales, datedim where sssolddatesk = ddatesk and dmonth_seq between 1176 and 1176+11 group by ssstoresk, ssitemsk) sc where sb.ssstoresk = sc.ssstoresk and sc.revenue <= 0.1 * sb.ave and sstoresk = sc.ssstoresk and iitemsk =

order by sstorename, iitemdesc limit 100; -- query 66 select wwarehousename ,wwarehousesq_ft ,w_city ,w_county ,w_state ,w_country ,ship_carriers ,year ,sum(jansales) as jansales ,sum(febsales) as febsales ,sum(marsales) as marsales ,sum(aprsales) as aprsales ,sum(maysales) as maysales ,sum(junsales) as junsales ,sum(julsales) as julsales ,sum(augsales) as augsales ,sum(sepsales) as sepsales ,sum(octsales) as octsales ,sum(novsales) as novsales ,sum(decsales) as decsales ,sum(jansales/wwarehousesqft) as jansalespersqfoot ,sum(febsales/wwarehousesqft) as febsalespersqfoot ,sum(marsales/wwarehousesqft) as marsalespersqfoot ,sum(aprsales/wwarehousesqft) as aprsalespersqfoot ,sum(maysales/wwarehousesqft) as maysalespersqfoot ,sum(junsales/wwarehousesqft) as junsalespersqfoot ,sum(julsales/wwarehousesqft) as julsalespersqfoot ,sum(augsales/wwarehousesqft) as augsalespersqfoot ,sum(sepsales/wwarehousesqft) as sepsalespersqfoot ,sum(octsales/wwarehousesqft) as octsalespersqfoot ,sum(novsales/wwarehousesqft) as novsalespersqfoot ,sum(decsales/wwarehousesqft) as decsalespersqfoot ,sum(jannet) as jannet ,sum(febnet) as febnet ,sum(marnet) as marnet ,sum(aprnet) as aprnet ,sum(maynet) as maynet ,sum(junnet) as junnet ,sum(julnet) as julnet ,sum(augnet) as augnet ,sum(sepnet) as sepnet ,sum(octnet) as octnet ,sum(novnet) as novnet ,sum(decnet) as decnet from ( select wwarehousename ,wwarehousesq_ft ,w_city ,w_county ,w_state ,w_country ,'DHL' || ',' || 'BARIAN' as ship_carriers ,d_year as year ,sum(case when d_moy = 1 then wsextsalesprice* wsquantity else 0 end) as jan_sales ,sum(case when d_moy = 2 then wsextsalesprice* wsquantity else 0 end) as feb_sales ,sum(case when d_moy = 3 then wsextsalesprice* wsquantity else 0 end) as mar_sales ,sum(case when d_moy = 4 then wsextsalesprice* wsquantity else 0 end) as apr_sales ,sum(case when d_moy = 5 then wsextsalesprice* wsquantity else 0 end) as may_sales ,sum(case when d_moy = 6 then wsextsalesprice* wsquantity else 0 end) as jun_sales ,sum(case when d_moy = 7 then wsextsalesprice* wsquantity else 0 end) as jul_sales ,sum(case when d_moy = 8 then wsextsalesprice* wsquantity else 0 end) as aug_sales ,sum(case when d_moy = 9 then wsextsalesprice* wsquantity else 0 end) as sep_sales ,sum(case when d_moy = 10 then wsextsalesprice* wsquantity else 0 end) as oct_sales ,sum(case when d_moy = 11 then wsextsalesprice* wsquantity else 0 end) as nov_sales ,sum(case when d_moy = 12 then wsextsalesprice* wsquantity else 0 end) as dec_sales ,sum(case when d_moy = 1 then wsnetpaid * wsquantity else 0 end) as jannet ,sum(case when d_moy = 2 then wsnetpaid * wsquantity else 0 end) as febnet ,sum(case when d_moy = 3 then wsnetpaid * wsquantity else 0 end) as marnet ,sum(case when d_moy = 4 then wsnetpaid * wsquantity else 0 end) as aprnet ,sum(case when d_moy = 5 then wsnetpaid * wsquantity else 0 end) as maynet ,sum(case when d_moy = 6 then wsnetpaid * wsquantity else 0 end) as junnet ,sum(case when d_moy = 7 then wsnetpaid * wsquantity else 0 end) as julnet ,sum(case when d_moy = 8 then wsnetpaid * wsquantity else 0 end) as augnet ,sum(case when d_moy = 9 then wsnetpaid * wsquantity else 0 end) as sepnet ,sum(case when d_moy = 10 then wsnetpaid * wsquantity else 0 end) as octnet ,sum(case when d_moy = 11 then wsnetpaid * wsquantity else 0 end) as novnet ,sum(case when d_moy = 12 then wsnetpaid * wsquantity else 0 end) as decnet from web_sales ,warehouse ,date_dim ,time_dim ,ship_mode where wswarehousesk = wwarehousesk and wssolddatesk = ddate_sk and wssoldtimesk = ttime_sk and wsshipmodesk = smshipmodesk and d_year = 2001 and t_time between 30838 and 30838+28800 and sm_carrier in ('DHL','BARIAN') group by wwarehousename ,wwarehousesq_ft ,w_city ,w_county ,w_state ,w_country ,d_year union all select wwarehousename ,wwarehousesq_ft ,w_city ,w_county ,w_state ,w_country ,'DHL' || ',' || 'BARIAN' as ship_carriers ,d_year as year ,sum(case when d_moy = 1 then cssalesprice* csquantity else 0 end) as jansales ,sum(case when d_moy = 2 then cssalesprice* csquantity else 0 end) as febsales ,sum(case when d_moy = 3 then cssalesprice* csquantity else 0 end) as marsales ,sum(case when d_moy = 4 then cssalesprice* csquantity else 0 end) as aprsales ,sum(case when d_moy = 5 then cssalesprice* csquantity else 0 end) as maysales ,sum(case when d_moy = 6 then cssalesprice* csquantity else 0 end) as junsales ,sum(case when d_moy = 7 then cssalesprice* csquantity else 0 end) as julsales ,sum(case when d_moy = 8 then cssalesprice* csquantity else 0 end) as augsales ,sum(case when d_moy = 9 then cssalesprice* csquantity else 0 end) as sepsales ,sum(case when d_moy = 10 then cssalesprice* csquantity else 0 end) as octsales ,sum(case when d_moy = 11 then cssalesprice* csquantity else 0 end) as novsales ,sum(case when d_moy = 12 then cssalesprice* csquantity else 0 end) as decsales ,sum(case when d_moy = 1 then csnetpaidinctax * csquantity else 0 end) as jannet ,sum(case when d_moy = 2 then csnetpaidinctax * csquantity else 0 end) as febnet ,sum(case when d_moy = 3 then csnetpaidinctax * csquantity else 0 end) as marnet ,sum(case when d_moy = 4 then csnetpaidinctax * csquantity else 0 end) as aprnet ,sum(case when d_moy = 5 then csnetpaidinctax * csquantity else 0 end) as maynet ,sum(case when d_moy = 6 then csnetpaidinctax * csquantity else 0 end) as junnet ,sum(case when d_moy = 7 then csnetpaidinctax * csquantity else 0 end) as julnet ,sum(case when d_moy = 8 then csnetpaidinctax * csquantity else 0 end) as augnet ,sum(case when d_moy = 9 then csnetpaidinctax * csquantity else 0 end) as sepnet ,sum(case when d_moy = 10 then csnetpaidinctax * csquantity else 0 end) as octnet ,sum(case when d_moy = 11 then csnetpaidinctax * csquantity else 0 end) as novnet ,sum(case when d_moy = 12 then csnetpaidinctax * csquantity else 0 end) as decnet from catalog_sales ,warehouse ,date_dim ,time_dim ,ship_mode where cswarehousesk = wwarehousesk and cssolddatesk = ddate_sk and cssoldtimesk = ttime_sk and csshipmodesk = smshipmodesk and d_year = 2001 and t_time between 30838 AND 30838+28800 and sm_carrier in ('DHL','BARIAN') group by wwarehousename ,wwarehousesq_ft ,w_city ,w_county ,w_state ,w_country ,d_year ) x group by wwarehousename ,wwarehousesq_ft ,w_city ,w_county ,w_state ,w_country ,ship_carriers ,year order by wwarehousename limit 100; -- query 67 select * from (select i_category ,i_class ,i_brand ,iproductname ,d_year ,d_qoy ,d_moy ,sstoreid ,sumsales ,rank() over (partition by i_category order by sumsales desc) rk from (select i_category ,i_class ,i_brand ,iproductname ,d_year ,d_qoy ,d_moy ,sstoreid ,sum(coalesce(sssalesprice*ss_quantity,0)) sumsales from store_sales ,date_dim ,store ,item where sssolddatesk=ddate_sk and ssitemsk=iitemsk and ssstoresk = sstoresk and dmonthseq between 1200 and 1200+11 group by rollup(icategory, iclass, ibrand, iproductname, dyear, dqoy, dmoy,sstoreid))dw1) dw2 where rk <= 100 order by i_category ,i_class ,i_brand ,iproductname ,d_year ,d_qoy ,d_moy ,sstoreid ,sumsales ,rk limit 100; -- query 68 select clastname ,cfirstname ,ca_city ,bought_city ,ssticketnumber ,extended_price ,extended_tax ,list_price from (select ssticketnumber ,sscustomersk ,cacity boughtcity ,sum(ssextsalesprice) extendedprice ,sum(ssextlistprice) listprice ,sum(ssexttax) extended_tax from store_sales ,date_dim ,store ,household_demographics ,customer_address where storesales.sssolddatesk = datedim.ddate_sk and storesales.ssstoresk = store.sstore_sk and storesales.sshdemosk = householddemographics.hddemosk and storesales.ssaddrsk = customeraddress.caaddresssk and datedim.ddom between 1 and 2 and (householddemographics.hddep_count = 4 or householddemographics.hdvehicle_count= 3) and datedim.dyear in (1999,1999+1,1999+2) and store.s_city in ('Fairview','Midway') group by ssticketnumber ,sscustomersk ,ssaddrsk,ca_city) dn ,customer ,customeraddress currentaddr where sscustomersk = ccustomersk and customer.ccurrentaddrsk = currentaddr.caaddresssk and currentaddr.cacity <> bought_city order by clastname ,ssticketnumber limit 100; -- query 69 select cd_gender, cdmaritalstatus, cdeducationstatus, count(*) cnt1, cdpurchaseestimate, count(*) cnt2, cdcreditrating, count(*) cnt3 from customer c,customeraddress ca,customerdemographics where c.ccurrentaddrsk = ca.caaddress_sk and ca_state in ('KY', 'GA', 'NM') and cddemosk = c.ccurrentcdemo_sk and exists (select * from storesales,datedim where c.ccustomersk = sscustomersk and sssolddatesk = ddate_sk and d_year = 2001 and d_moy between 4 and 4+2) and (not exists (select * from websales,datedim where c.ccustomersk = wsbillcustomer_sk and wssolddatesk = ddate_sk and d_year = 2001 and d_moy between 4 and 4+2) and not exists (select * from catalogsales,datedim where c.ccustomersk = csshipcustomer_sk and cssolddatesk = ddate_sk and d_year = 2001 and d_moy between 4 and 4+2)) group by cd_gender, cdmaritalstatus, cdeducationstatus, cdpurchaseestimate, cdcreditrating order by cd_gender, cdmaritalstatus, cdeducationstatus, cdpurchaseestimate, cdcreditrating limit 100; -- query 70 select sum(ssnetprofit) as total_sum ,s_state ,s_county ,grouping(sstate)+grouping(scounty) as lochierarchy ,rank() over ( partition by grouping(sstate)+grouping(scounty), case when grouping(scounty) = 0 then sstate end order by sum(ssnetprofit) desc) as rankwithinparent from store_sales ,date_dim d1 ,store where d1.dmonthseq between 1200 and 1200+11 and d1.ddatesk = sssolddate_sk and sstoresk = ssstoresk and s_state in ( select s_state from (select sstate as sstate, rank() over ( partition by sstate order by sum(ssnet_profit) desc) as ranking from storesales, store, datedim where dmonthseq between 1200 and 1200+11 and ddatesk = sssolddate_sk and sstoresk = ssstoresk group by s_state ) tmp1 where ranking <= 5 ) group by rollup(sstate,scounty) order by lochierarchy desc ,case when lochierarchy = 0 then s_state end ,rankwithinparent limit 100; -- query 71 select ibrandid brandid, ibrand brand,thour,tminute, sum(extprice) extprice from item, (select wsextsalesprice as extprice, wssolddatesk as solddate_sk, wsitemsk as solditemsk, wssoldtimesk as timesk from websales,datedim where ddatesk = wssolddate_sk and d_moy=11 and d_year=1999 union all select csextsalesprice as extprice, cssolddatesk as solddate_sk, csitemsk as solditemsk, cssoldtimesk as timesk from catalogsales,datedim where ddatesk = cssolddate_sk and d_moy=11 and d_year=1999 union all select ssextsalesprice as extprice, sssolddatesk as solddate_sk, ssitemsk as solditemsk, sssoldtimesk as timesk from storesales,datedim where ddatesk = sssolddate_sk and d_moy=11 and d_year=1999 ) tmp,time_dim where solditemsk = iitemsk and imanagerid=1 and timesk = ttime_sk and (tmealtime = 'breakfast' or tmealtime = 'dinner') group by ibrand, ibrandid,thour,t_minute order by extprice desc, ibrand_id ; -- query 72 select iitemdesc ,wwarehousename ,d1.dweekseq ,sum(case when ppromosk is null then 1 else 0 end) no_promo ,sum(case when ppromosk is not null then 1 else 0 end) promo ,count(*) total_cnt from catalog_sales join inventory on (csitemsk = invitemsk) join warehouse on (wwarehousesk=invwarehousesk) join item on (iitemsk = csitemsk) join customerdemographics on (csbillcdemosk = cddemosk) join householddemographics on (csbillhdemosk = hddemosk) join datedim d1 on (cssolddatesk = d1.ddatesk) join datedim d2 on (invdatesk = d2.ddate_sk) join datedim d3 on (csshipdatesk = d3.ddatesk) left outer join promotion on (cspromosk=ppromosk) left outer join catalogreturns on (critemsk = csitemsk and crordernumber = csorder_number) where d1.dweekseq = d2.dweekseq and invquantityonhand < csquantity and d3.ddate > d1.ddate + 5 and hdbuypotential = '>10000' and d1.d_year = 1999 and cdmaritalstatus = 'D' group by

order by totalcnt desc, iitemdesc, wwarehousename, dweek_seq limit 100; -- query 73 select clastname ,cfirstname ,c_salutation ,cpreferredcust_flag ,ssticketnumber ,cnt from (select ssticketnumber ,sscustomersk ,count(*) cnt from storesales,datedim,store,household_demographics where storesales.sssolddatesk = datedim.ddate_sk and storesales.ssstoresk = store.sstore_sk and storesales.sshdemosk = householddemographics.hddemosk and datedim.ddom between 1 and 2 and (householddemographics.hdbuy_potential = '>10000' or householddemographics.hdbuy_potential = 'Unknown') and householddemographics.hdvehicle_count > 0 and case when householddemographics.hdvehicle_count > 0 then householddemographics.hddepcount/ householddemographics.hdvehiclecount else null end > 1 and datedim.dyear in (1999,1999+1,1999+2) and store.s_county in ('Williamson County', 'Franklin Parish', 'Bronx County', 'Orange County') group by ssticketnumber,sscustomersk) dj,customer where sscustomersk = ccustomersk and cnt between 1 and 5 order by cnt desc, clastname asc; -- query 74 with year_total as ( select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,d_year as year ,sum(ssnetpaid) year_total ,'s' sale_type from customer ,store_sales ,date_dim where ccustomersk = sscustomersk and sssolddatesk = ddate_sk and d_year in (2001,2001+1) group by ccustomerid ,cfirstname ,clastname ,d_year union all select ccustomerid customer_id ,cfirstname customerfirstname ,clastname customerlastname ,d_year as year ,sum(wsnetpaid) year_total ,'w' sale_type from customer ,web_sales ,date_dim where ccustomersk = wsbillcustomer_sk and wssolddatesk = ddate_sk and d_year in (2001,2001+1) group by ccustomerid ,cfirstname ,clastname ,d_year ) select tssecyear.customerid, tssecyear.customerfirstname, tssecyear.customerlast_name from yeartotal ts_firstyear ,yeartotal ts_secyear ,yeartotal tw_firstyear ,yeartotal tw_secyear where tssecyear.customerid = tsfirstyear.customerid and tsfirstyear.customerid = twsecyear.customerid and tsfirstyear.customerid = twfirstyear.customerid and tsfirstyear.sale_type = 's' and twfirstyear.sale_type = 'w' and tssecyear.sale_type = 's' and twsecyear.sale_type = 'w' and tsfirstyear.year = 2001 and tssecyear.year = 2001+1 and twfirstyear.year = 2001 and twsecyear.year = 2001+1 and tsfirstyear.year_total > 0 and twfirstyear.year_total > 0 and case when twfirstyear.yeartotal > 0 then twsecyear.yeartotal / twfirstyear.year_total else null end > case when tsfirstyear.yeartotal > 0 then tssecyear.yeartotal / tsfirstyear.year_total else null end order by 1, 1, 1 limit 100; -- query 75 WITH all_sales AS ( SELECT d_year ,ibrandid ,iclassid ,icategoryid ,imanufactid ,SUM(salescnt) AS salescnt ,SUM(salesamt) AS salesamt FROM (SELECT d_year ,ibrandid ,iclassid ,icategoryid ,imanufactid ,csquantity - COALESCE(crreturnquantity,0) AS salescnt ,csextsalesprice - COALESCE(crreturnamount,0.0) AS salesamt FROM catalogsales JOIN item ON iitemsk=csitem_sk JOIN datedim ON ddatesk=cssolddatesk LEFT JOIN catalogreturns ON (csordernumber=crorder_number AND csitemsk=critemsk) WHERE i_category='Books' UNION SELECT d_year ,ibrandid ,iclassid ,icategoryid ,imanufactid ,ssquantity - COALESCE(srreturnquantity,0) AS salescnt ,ssextsalesprice - COALESCE(srreturnamt,0.0) AS salesamt FROM storesales JOIN item ON iitemsk=ssitem_sk JOIN datedim ON ddatesk=sssolddatesk LEFT JOIN storereturns ON (ssticketnumber=srticket_number AND ssitemsk=sritemsk) WHERE i_category='Books' UNION SELECT d_year ,ibrandid ,iclassid ,icategoryid ,imanufactid ,wsquantity - COALESCE(wrreturnquantity,0) AS salescnt ,wsextsalesprice - COALESCE(wrreturnamt,0.0) AS salesamt FROM websales JOIN item ON iitemsk=wsitem_sk JOIN datedim ON ddatesk=wssolddatesk LEFT JOIN webreturns ON (wsordernumber=wrorder_number AND wsitemsk=writemsk) WHERE icategory='Books') salesdetail GROUP BY dyear, ibrandid, iclassid, icategoryid, imanufact_id) SELECT prevyr.dyear AS prev_year ,curryr.dyear AS year ,curryr.ibrand_id ,curryr.iclass_id ,curryr.icategory_id ,curryr.imanufact_id ,prevyr.salescnt AS prevyrcnt ,curryr.salescnt AS curryrcnt ,curryr.salescnt-prevyr.salescnt AS salescntdiff ,curryr.salesamt-prevyr.salesamt AS salesamtdiff FROM allsales curryr, allsales prevyr WHERE curryr.ibrandid=prevyr.ibrandid AND curryr.iclassid=prevyr.iclassid AND curryr.icategoryid=prevyr.icategoryid AND curryr.imanufactid=prevyr.imanufactid AND curryr.dyear=2002 AND prevyr.dyear=2002-1 AND CAST(curryr.salescnt AS DECIMAL(17,2))/CAST(prevyr.salescnt AS

ORDER BY salescntdiff,salesamtdiff limit 100; -- query 76 select channel, colname, dyear, dqoy, icategory, COUNT(*) salescnt, SUM(extsalesprice) salesamt FROM ( SELECT 'store' as channel, 'ssstoresk' colname, dyear, dqoy, icategory, ssextsalesprice extsales_price FROM storesales, item, datedim WHERE ssstoresk IS NULL AND sssolddatesk=ddate_sk AND ssitemsk=iitemsk UNION ALL SELECT 'web' as channel, 'wsshipcustomersk' colname, dyear, dqoy, icategory, wsextsalesprice extsalesprice FROM websales, item, datedim WHERE wsshipcustomer_sk IS NULL AND wssolddatesk=ddate_sk AND wsitemsk=iitemsk UNION ALL SELECT 'catalog' as channel, 'csshipaddrsk' colname, dyear, dqoy, icategory, csextsalesprice extsalesprice FROM catalogsales, item, datedim WHERE csshipaddr_sk IS NULL AND cssolddatesk=ddate_sk AND csitemsk=iitemsk) foo GROUP BY channel, colname, dyear, dqoy, icategory ORDER BY channel, colname, dyear, dqoy, icategory limit 100; -- query 77 with ss as (select sstoresk, sum(ssextsales_price) as sales, sum(ssnetprofit) as profit from store_sales, date_dim, store where sssolddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and ssstoresk = sstoresk group by sstoresk) , sr as (select sstoresk, sum(srreturnamt) as returns, sum(srnetloss) as profit_loss from store_returns, date_dim, store where srreturneddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and srstoresk = sstoresk group by sstoresk), cs as (select cscallcenter_sk, sum(csextsales_price) as sales, sum(csnetprofit) as profit from catalog_sales, date_dim where cssolddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) group by cscallcenter_sk ), cr as (select crcallcenter_sk, sum(crreturnamount) as returns, sum(crnetloss) as profit_loss from catalog_returns, date_dim where crreturneddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) group by crcallcenter_sk ), ws as ( select wpwebpage_sk, sum(wsextsales_price) as sales, sum(wsnetprofit) as profit from web_sales, date_dim, web_page where wssolddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and wswebpagesk = wpwebpagesk group by wpwebpage_sk), wr as (select wpwebpage_sk, sum(wrreturnamt) as returns, sum(wrnetloss) as profit_loss from web_returns, date_dim, web_page where wrreturneddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and wrwebpagesk = wpwebpagesk group by wpwebpage_sk) select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit from (select 'store channel' as channel , ss.sstoresk as id , sales , coalesce(returns, 0) as returns , (profit - coalesce(profit_loss,0)) as profit from ss left join sr on ss.sstoresk = sr.sstoresk union all select 'catalog channel' as channel , cscallcenter_sk as id , sales , returns , (profit - profit_loss) as profit from cs , cr union all select 'web channel' as channel , ws.wpwebpage_sk as id , sales , coalesce(returns, 0) returns , (profit - coalesce(profit_loss,0)) as profit from ws left join wr on ws.wpwebpagesk = wr.wpwebpagesk ) x group by rollup (channel, id) order by channel ,id limit 100; -- query 78 with ws as (select dyear AS wssoldyear, wsitem_sk, wsbillcustomersk wscustomer_sk, sum(wsquantity) wsqty, sum(wswholesalecost) ws_wc, sum(wssalesprice) ws_sp from web_sales left join webreturns on wrordernumber=wsordernumber and wsitemsk=writem_sk join datedim on wssolddatesk = ddatesk where wrordernumber is null group by dyear, wsitemsk, wsbillcustomersk ), cs as (select dyear AS cssoldyear, csitem_sk, csbillcustomersk cscustomer_sk, sum(csquantity) csqty, sum(cswholesalecost) cs_wc, sum(cssalesprice) cs_sp from catalog_sales left join catalogreturns on crordernumber=csordernumber and csitemsk=critem_sk join datedim on cssolddatesk = ddatesk where crordernumber is null group by dyear, csitemsk, csbillcustomersk ), ss as (select dyear AS sssoldyear, ssitem_sk, sscustomersk, sum(ssquantity) ssqty, sum(sswholesalecost) ss_wc, sum(sssalesprice) ss_sp from store_sales left join storereturns on srticketnumber=ssticketnumber and ssitemsk=sritem_sk join datedim on sssolddatesk = ddatesk where srticketnumber is null group by dyear, ssitemsk, sscustomer_sk ) select sssoldyear, ssitemsk, sscustomersk, round(ssqty/(coalesce(wsqty,0)+coalesce(cs_qty,0)),2) ratio, ssqty storeqty, sswc storewholesalecost, sssp storesalesprice, coalesce(wsqty,0)+coalesce(csqty,0) otherchanqty, coalesce(wswc,0)+coalesce(cswc,0) otherchanwholesale_cost, coalesce(wssp,0)+coalesce(cssp,0) otherchansales_price from ss left join ws on (wssoldyear=sssoldyear and wsitemsk=ssitemsk and wscustomersk=sscustomersk) left join cs on (cssoldyear=sssoldyear and csitemsk=ssitemsk and cscustomersk=sscustomersk) where (coalesce(wsqty,0)>0 or coalesce(csqty, 0)>0) and sssoldyear=2000 order by sssoldyear, ssitemsk, sscustomersk, ssqty desc, sswc desc, ss_sp desc, otherchanqty, otherchanwholesale_cost, otherchansales_price, ratio limit 100; -- query 79 select clastname,cfirstname,substr(scity,1,30),ssticket_number,amt,profit from (select ssticketnumber ,sscustomersk ,store.s_city ,sum(sscouponamt) amt ,sum(ssnetprofit) profit from storesales,datedim,store,household_demographics where storesales.sssolddatesk = datedim.ddate_sk and storesales.ssstoresk = store.sstore_sk and storesales.sshdemosk = householddemographics.hddemosk and (householddemographics.hddepcount = 6 or householddemographics.hdvehiclecount > 2) and datedim.ddow = 1 and datedim.dyear in (1999,1999+1,1999+2) and store.snumberemployees between 200 and 295 group by

ms,customer where sscustomersk = ccustomersk order by clastname,cfirstname,substr(s_city,1,30), profit limit 100; -- query 80 with ssr as (select sstoreid as store_id, sum(ssextsales_price) as sales, sum(coalesce(srreturnamt, 0)) as returns, sum(ssnetprofit - coalesce(srnetloss, 0)) as profit from storesales left outer join storereturns on (ssitemsk = sritemsk and ssticketnumber = srticketnumber), date_dim, store, item, promotion where sssolddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and ssstoresk = sstoresk and ssitemsk = iitemsk and icurrentprice > 50 and sspromosk = ppromosk and pchanneltv = 'N' group by sstoreid) , csr as (select cpcatalogpageid as catalogpage_id, sum(csextsales_price) as sales, sum(coalesce(crreturnamount, 0)) as returns, sum(csnetprofit - coalesce(crnetloss, 0)) as profit from catalogsales left outer join catalogreturns on (csitemsk = critemsk and csordernumber = crordernumber), date_dim, catalog_page, item, promotion where cssolddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and cscatalogpagesk = cpcatalogpagesk and csitemsk = iitemsk and icurrentprice > 50 and cspromosk = ppromosk and pchanneltv = 'N' group by cpcatalogpage_id) , wsr as (select websiteid, sum(wsextsales_price) as sales, sum(coalesce(wrreturnamt, 0)) as returns, sum(wsnetprofit - coalesce(wrnetloss, 0)) as profit from websales left outer join webreturns on (wsitemsk = writemsk and wsordernumber = wrordernumber), date_dim, web_site, item, promotion where wssolddatesk = ddate_sk and d_date between cast('2000-08-23' as date) and date_add(cast('2000-08-23' as date), 30) and wswebsitesk = website_sk and wsitemsk = iitemsk and icurrentprice > 50 and wspromosk = ppromosk and pchanneltv = 'N' group by websiteid) select channel , id , sum(sales) as sales , sum(returns) as returns , sum(profit) as profit from (select 'store channel' as channel , 'store' || store_id as id , sales , returns , profit from ssr union all select 'catalog channel' as channel , 'catalogpage' || catalogpage_id as id , sales , returns , profit from csr union all select 'web channel' as channel , 'website' || website_id as id , sales , returns , profit from wsr ) x group by rollup (channel, id) order by channel ,id limit 100; -- query 81 with customertotalreturn as (select crreturningcustomersk as ctrcustomer_sk ,castate as ctrstate, sum(crreturnamtinctax) as ctrtotalreturn from catalog_returns ,date_dim ,customer_address where crreturneddatesk = ddate_sk and d_year =2000 and crreturningaddrsk = caaddress_sk group by crreturningcustomer_sk ,ca_state ) select ccustomerid,csalutation,cfirstname,clastname,castreetnumber,castreet_name ,castreettype,casuitenumber,cacity,cacounty,castate,cazip,cacountry,cagmt_offset ,calocationtype,ctrtotalreturn from customertotalreturn ctr1 ,customer_address ,customer where ctr1.ctrtotalreturn > (select avg(ctrtotalreturn)*1.2 from customertotalreturn ctr2 where ctr1.ctrstate = ctr2.ctrstate) and caaddresssk = ccurrentaddr_sk and ca_state = 'GA' and ctr1.ctrcustomersk = ccustomersk order by ccustomerid,csalutation,cfirstname,clastname,castreetnumber,castreet_name ,castreettype,casuitenumber,cacity,cacounty,castate,cazip,cacountry,cagmt_offset ,calocationtype,ctrtotalreturn limit 100; -- query 82 select iitemid ,iitemdesc ,icurrentprice from item, inventory, datedim, storesales where icurrentprice between 62 and 62+30 and invitemsk = iitemsk and ddatesk=invdatesk and ddate between cast('2000-05-25' as date) and dateadd(cast('2000-05-25' as date), 60) and imanufactid in (129,270,821,423) and invquantityon_hand between 100 and 500 and ssitemsk = iitemsk group by iitemid,iitemdesc,icurrentprice order by iitemid limit 100; -- query 83 with sr_items as (select iitemid item_id, sum(srreturnquantity) sritemqty from store_returns, item, date_dim where sritemsk = iitemsk and d_date in (select d_date from date_dim where dweekseq in (select dweekseq from date_dim where d_date in ('2000-06-30','2000-09-27','2000-11-17'))) and srreturneddatesk = ddate_sk group by iitemid), cr_items as (select iitemid item_id, sum(crreturnquantity) critemqty from catalog_returns, item, date_dim where critemsk = iitemsk and d_date in (select d_date from date_dim where dweekseq in (select dweekseq from date_dim where d_date in ('2000-06-30','2000-09-27','2000-11-17'))) and crreturneddatesk = ddate_sk group by iitemid), wr_items as (select iitemid item_id, sum(wrreturnquantity) writemqty from web_returns, item, date_dim where writemsk = iitemsk and d_date in (select d_date from date_dim where dweekseq in (select dweekseq from date_dim where d_date in ('2000-06-30','2000-09-27','2000-11-17'))) and wrreturneddatesk = ddate_sk group by iitemid) select sritems.itemid ,sritemqty ,sritemqty/(sritemqty+critemqty+writemqty)/3.0 * 100 sr_dev ,critemqty ,critemqty/(sritemqty+critemqty+writemqty)/3.0 * 100 cr_dev ,writemqty ,writemqty/(sritemqty+critemqty+writemqty)/3.0 * 100 wr_dev ,(sritemqty+critemqty+writemqty)/3.0 average from sr_items ,cr_items ,wr_items where sritems.itemid=critems.itemid and sritems.itemid=writems.itemid order by

,sritemqty limit 100; -- query 84 select ccustomerid as customer_id , coalesce(clastname,'') || ', ' || coalesce(cfirstname,'') as customername from customer ,customer_address ,customer_demographics ,household_demographics ,income_band ,store_returns where ca_city = 'Edgewood' and ccurrentaddrsk = caaddress_sk and iblowerbound >= 38128 and ibupperbound <= 38128 + 50000 and ibincomebandsk = hdincomebandsk and cddemosk = ccurrentcdemo_sk and hddemosk = ccurrenthdemo_sk and srcdemosk = cddemosk order by ccustomerid limit 100; -- query 85 select substr(rreasondesc,1,20) ,avg(ws_quantity) ,avg(wrrefundedcash) ,avg(wr_fee) from websales, webreturns, webpage, customerdemographics cd1, customerdemographics cd2, customeraddress, date_dim, reason where wswebpagesk = wpwebpagesk and wsitemsk = writemsk and wsordernumber = wrordernumber and wssolddatesk = ddatesk and dyear = 2000 and cd1.cddemosk = wrrefundedcdemo_sk and cd2.cddemosk = wrreturningcdemo_sk and caaddresssk = wrrefundedaddr_sk and rreasonsk = wrreasonsk and ( ( cd1.cdmaritalstatus = 'M' and cd1.cdmaritalstatus = cd2.cdmaritalstatus and cd1.cdeducationstatus = 'Advanced Degree' and cd1.cdeducationstatus = cd2.cdeducationstatus and wssalesprice between 100.00 and 150.00 ) or ( cd1.cdmaritalstatus = 'S' and cd1.cdmaritalstatus = cd2.cdmaritalstatus and cd1.cdeducationstatus = 'College' and cd1.cdeducationstatus = cd2.cdeducationstatus and wssalesprice between 50.00 and 100.00 ) or ( cd1.cdmaritalstatus = 'W' and cd1.cdmaritalstatus = cd2.cdmaritalstatus and cd1.cdeducationstatus = '2 yr Degree' and cd1.cdeducationstatus = cd2.cdeducationstatus and wssalesprice between 150.00 and 200.00 ) ) and ( ( ca_country = 'United States' and ca_state in ('IN', 'OH', 'NJ') and wsnetprofit between 100 and 200 ) or ( ca_country = 'United States' and ca_state in ('WI', 'CT', 'KY') and wsnetprofit between 150 and 300 ) or ( ca_country = 'United States' and ca_state in ('LA', 'IA', 'AR') and wsnetprofit between 50 and 250 ) ) group by rreasondesc order by substr(rreasondesc,1,20) ,avg(ws_quantity) ,avg(wrrefundedcash) ,avg(wr_fee) limit 100; -- query 86 select sum(wsnetpaid) as total_sum ,i_category ,i_class ,grouping(icategory)+grouping(iclass) as lochierarchy ,rank() over ( partition by grouping(icategory)+grouping(iclass), case when grouping(iclass) = 0 then icategory end order by sum(wsnetpaid) desc) as rankwithinparent from web_sales ,date_dim d1 ,item where d1.dmonthseq between 1200 and 1200+11 and d1.ddatesk = wssolddate_sk and iitemsk = wsitemsk group by rollup(icategory,iclass) order by lochierarchy desc, case when lochierarchy = 0 then i_category end, rankwithinparent limit 100; -- query 87 select count(*) from ((select distinct clastname, cfirstname, d_date from storesales, datedim, customer where storesales.sssolddatesk = datedim.ddate_sk and storesales.sscustomersk = customer.ccustomer_sk and dmonthseq between 1200 and 1200+11) except (select distinct clastname, cfirstname, d_date from catalogsales, datedim, customer where catalogsales.cssolddatesk = datedim.ddate_sk and catalogsales.csbillcustomersk = customer.ccustomersk and dmonthseq between 1200 and 1200+11) except (select distinct clastname, cfirstname, d_date from websales, datedim, customer where websales.wssolddatesk = datedim.ddate_sk and websales.wsbillcustomersk = customer.ccustomersk and dmonthseq between 1200 and 1200+11) ) cool_cust ; -- query 88 select * from (select count(*) h830to_9 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 8 and timedim.tminute >= 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s1, (select count(*) h9to9_30 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 9 and timedim.tminute < 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s2, (select count(*) h930to_10 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 9 and timedim.tminute >= 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s3, (select count(*) h10to10_30 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and

= 10 and timedim.tminute < 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s4, (select count(*) h1030to_11 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 10 and timedim.tminute >= 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s5, (select count(*) h11to11_30 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 11 and timedim.tminute < 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s6, (select count(*) h1130to_12 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 11 and timedim.tminute >= 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s7, (select count(*) h12to12_30 from storesales, householddemographics , time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 12 and timedim.tminute < 30 and ((householddemographics.hddepcount = 4 and householddemographics.hdvehiclecount<=4+2) or (householddemographics.hddepcount = 2 and householddemographics.hdvehiclecount<=2+2) or (householddemographics.hddepcount = 0 and householddemographics.hdvehiclecount<=0+2)) and store.sstorename = 'ese') s8 ; -- query 89 select * from( select icategory, iclass, i_brand, sstorename, scompanyname, d_moy, sum(sssalesprice) sum_sales, avg(sum(sssalesprice)) over (partition by icategory, ibrand, sstorename, scompanyname) avgmonthlysales from item, storesales, datedim, store where ssitemsk = iitemsk and sssolddatesk = ddate_sk and ssstoresk = sstoresk and d_year in (1999) and ((i_category in ('Books','Electronics','Sports') and i_class in ('computers','stereo','football') ) or (i_category in ('Men','Jewelry','Women') and i_class in ('shirts','birdal','dresses') )) group by icategory, iclass, i_brand, sstorename, scompanyname, d_moy) tmp1 where case when (avgmonthlysales <> 0) then (abs(sumsales - avgmonthlysales) / avgmonthly_sales) else null end > 0.1 order by sumsales - avgmonthlysales, sstore_name limit 100; -- query 90 select cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) ampmratio from ( select count(*) amc from websales, householddemographics , timedim, webpage where wssoldtimesk = timedim.ttimesk and wsshiphdemosk = householddemographics.hddemosk and wswebpagesk = webpage.wpwebpage_sk and timedim.thour between 8 and 8+1 and householddemographics.hddep_count = 6 and webpage.wpchar_count between 5000 and 5200) at, ( select count(*) pmc from websales, householddemographics , timedim, webpage where wssoldtimesk = timedim.ttimesk and wsshiphdemosk = householddemographics.hddemosk and wswebpagesk = webpage.wpwebpage_sk and timedim.thour between 19 and 19+1 and householddemographics.hddep_count = 6 and webpage.wpchar_count between 5000 and 5200) pt order by ampmratio limit 100; -- query 91 select cccallcenterid CallCenter, ccname CallCenter_Name, cc_manager Manager, sum(crnetloss) Returns_Loss from call_center, catalog_returns, date_dim, customer, customer_address, customer_demographics, household_demographics where crcallcentersk = cccallcentersk and crreturneddatesk = ddate_sk and crreturningcustomersk= ccustomer_sk and cddemosk = ccurrentcdemo_sk and hddemosk = ccurrenthdemo_sk and caaddresssk = ccurrentaddr_sk and d_year = 1998 and d_moy = 11 and ( (cdmaritalstatus = 'M' and cdeducationstatus = 'Unknown') or(cdmaritalstatus = 'W' and cdeducationstatus = 'Advanced Degree')) and hdbuypotential like 'Unknown%' and cagmtoffset = -7 group by cccallcenterid,ccname,ccmanager,cdmaritalstatus,cdeducation_status order by sum(crnetloss) desc; -- query 92 select sum(wsextdiscount_amt) as "Excess Discount Amount" from web_sales ,item ,date_dim where imanufactid = 350 and iitemsk = wsitemsk and d_date between '2000-01-27' and date_add(cast('2000-01-27' as date), 90) and ddatesk = wssolddate_sk and wsextdiscount_amt > ( SELECT

* avg(wsextdiscount_amt) FROM web_sales ,date_dim WHERE wsitemsk = iitemsk and d_date between '2000-01-27' and date_add(cast('2000-01-27' as date), 90) and ddatesk = wssolddate_sk ) order by sum(wsextdiscount_amt) limit 100; -- query 93 select sscustomersk ,sum(act_sales) sumsales from (select ssitemsk ,ssticketnumber ,sscustomersk ,case when srreturnquantity is not null then (ssquantity-srreturnquantity)*sssales_price else (ssquantity*sssalesprice) end actsales from storesales left outer join storereturns on (sritemsk = ssitemsk and srticketnumber = ssticketnumber) ,reason where srreasonsk = rreasonsk and rreasondesc = 'reason 28') t group by sscustomersk order by sumsales, sscustomersk limit 100; -- query 94 select count(distinct wsordernumber) as "order count" ,sum(wsextship_cost) as "total shipping cost" ,sum(wsnetprofit) as "total net profit" from web_sales ws1 ,date_dim ,customer_address ,web_site where d_date between '1999-2-01' and date_add(cast('1999-2-01' as date), 60) and ws1.wsshipdatesk = ddate_sk and ws1.wsshipaddrsk = caaddress_sk and ca_state = 'IL' and ws1.wswebsitesk = website_sk and webcompanyname = 'pri' and exists (select * from web_sales ws2 where ws1.wsordernumber = ws2.wsordernumber and ws1.wswarehousesk <> ws2.wswarehousesk) and not exists(select * from web_returns wr1 where ws1.wsordernumber = wr1.wrordernumber) order by count(distinct wsordernumber) limit 100; -- query 95 with ws_wh as (select ws1.wsordernumber,ws1.wswarehousesk wh1,ws2.wswarehousesk wh2 from websales ws1,websales ws2 where ws1.wsordernumber = ws2.wsordernumber and ws1.wswarehousesk <> ws2.wswarehousesk) select count(distinct wsordernumber) as "order count" ,sum(wsextship_cost) as "total shipping cost" ,sum(wsnetprofit) as "total net profit" from web_sales ws1 ,date_dim ,customer_address ,web_site where d_date between '1999-2-01' and date_add(cast('1999-2-01' as date), 60) and ws1.wsshipdatesk = ddate_sk and ws1.wsshipaddrsk = caaddress_sk and ca_state = 'IL' and ws1.wswebsitesk = website_sk and webcompanyname = 'pri' and ws1.wsordernumber in (select wsordernumber from ws_wh) and ws1.wsordernumber in (select wrordernumber from webreturns,wswh where wrordernumber = wswh.wsorder_number) order by count(distinct wsordernumber) limit 100; -- query 96 select count(*) from store_sales ,household_demographics ,time_dim, store where sssoldtimesk = timedim.ttimesk and sshdemosk = householddemographics.hddemo_sk and ssstoresk = sstoresk and timedim.thour = 20 and timedim.tminute >= 30 and householddemographics.hddep_count = 7 and store.sstorename = 'ese' order by count(*) limit 100; -- query 97 with ssci as ( select sscustomersk customer_sk ,ssitemsk item_sk from storesales,datedim where sssolddatesk = ddate_sk and dmonthseq between 1200 and 1200 + 11 group by sscustomersk ,ssitemsk), csci as( select csbillcustomersk customersk ,csitemsk item_sk from catalogsales,datedim where cssolddatesk = ddate_sk and dmonthseq between 1200 and 1200 + 11 group by csbillcustomer_sk ,csitemsk) select sum(case when ssci.customersk is not null and csci.customersk is null then 1 else 0 end) store_only ,sum(case when ssci.customersk is null and csci.customersk is not null then 1 else 0 end) catalog_only ,sum(case when ssci.customersk is not null and csci.customersk is not null then 1 else 0 end) storeandcatalog from ssci full outer join csci on (ssci.customersk=csci.customersk and ssci.itemsk = csci.itemsk) limit 100; -- query 98 select iitemid ,iitemdesc ,i_category ,i_class ,icurrentprice ,sum(ssextsales_price) as itemrevenue ,sum(ssextsalesprice)*100/sum(sum(ssextsalesprice)) over (partition by i_class) as revenueratio from store_sales ,item ,date_dim where ssitemsk = iitemsk and i_category in ('Sports', 'Books', 'Home') and sssolddatesk = ddate_sk and d_date between cast('1999-02-22' as date) and date_add(cast('1999-02-22' as date), 30) group by iitemid ,iitemdesc ,i_category ,i_class ,icurrentprice order by i_category ,i_class ,iitemid ,iitemdesc ,revenueratio; -- query 99 select substr(wwarehousename,1,20) ,sm_type ,cc_name ,sum(case when (csshipdatesk - cssolddatesk <= 30 ) then 1 else 0 end) as "30 days" ,sum(case when (csshipdatesk - cssolddatesk > 30) and (csshipdatesk - cssolddatesk <= 60) then 1 else 0 end ) as "31-60 days" ,sum(case when (csshipdatesk - cssolddatesk > 60) and (csshipdatesk - cssolddatesk <= 90) then 1 else 0 end) as "61-90 days" ,sum(case when (csshipdatesk - cssolddatesk > 90) and (csshipdatesk - cssolddatesk <= 120) then 1 else 0 end) as "91-120 days" ,sum(case when (csshipdatesk - cssolddatesk > 120) then 1 else 0 end) as ">120 days" from catalog_sales ,warehouse ,ship_mode ,call_center