forked from agirish/tpcds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query65.sql
37 lines (37 loc) · 1.27 KB
/
query65.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- start query 65 in stream 0 using template query65.tpl
SELECT s_store_name,
i_item_desc,
sc.revenue,
i_current_price,
i_wholesale_cost,
i_brand
FROM store,
item,
(SELECT ss_store_sk,
Avg(revenue) AS ave
FROM (SELECT ss_store_sk,
ss_item_sk,
Sum(ss_sales_price) AS revenue
FROM store_sales,
date_dim
WHERE ss_sold_date_sk = d_date_sk
AND d_month_seq BETWEEN 1199 AND 1199 + 11
GROUP BY ss_store_sk,
ss_item_sk) sa
GROUP BY ss_store_sk) sb,
(SELECT ss_store_sk,
ss_item_sk,
Sum(ss_sales_price) AS revenue
FROM store_sales,
date_dim
WHERE ss_sold_date_sk = d_date_sk
AND d_month_seq BETWEEN 1199 AND 1199 + 11
GROUP BY ss_store_sk,
ss_item_sk) sc
WHERE sb.ss_store_sk = sc.ss_store_sk
AND sc.revenue <= 0.1 * sb.ave
AND s_store_sk = sc.ss_store_sk
AND i_item_sk = sc.ss_item_sk
ORDER BY s_store_name,
i_item_desc
LIMIT 100;