Advertisement
Guest User

Untitled

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