forked from agirish/tpcds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query9.sql
63 lines (63 loc) · 2.18 KB
/
query9.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- start query 9 in stream 0 using template query9.tpl
SELECT CASE
WHEN (SELECT Count(*)
FROM store_sales
WHERE ss_quantity BETWEEN 1 AND 20) > 3672 THEN
(SELECT Avg(ss_ext_list_price)
FROM store_sales
WHERE
ss_quantity BETWEEN 1 AND 20)
ELSE (SELECT Avg(ss_net_profit)
FROM store_sales
WHERE ss_quantity BETWEEN 1 AND 20)
END bucket1,
CASE
WHEN (SELECT Count(*)
FROM store_sales
WHERE ss_quantity BETWEEN 21 AND 40) > 3392 THEN
(SELECT Avg(ss_ext_list_price)
FROM store_sales
WHERE
ss_quantity BETWEEN 21 AND 40)
ELSE (SELECT Avg(ss_net_profit)
FROM store_sales
WHERE ss_quantity BETWEEN 21 AND 40)
END bucket2,
CASE
WHEN (SELECT Count(*)
FROM store_sales
WHERE ss_quantity BETWEEN 41 AND 60) > 32784 THEN
(SELECT Avg(ss_ext_list_price)
FROM store_sales
WHERE
ss_quantity BETWEEN 41 AND 60)
ELSE (SELECT Avg(ss_net_profit)
FROM store_sales
WHERE ss_quantity BETWEEN 41 AND 60)
END bucket3,
CASE
WHEN (SELECT Count(*)
FROM store_sales
WHERE ss_quantity BETWEEN 61 AND 80) > 26032 THEN
(SELECT Avg(ss_ext_list_price)
FROM store_sales
WHERE
ss_quantity BETWEEN 61 AND 80)
ELSE (SELECT Avg(ss_net_profit)
FROM store_sales
WHERE ss_quantity BETWEEN 61 AND 80)
END bucket4,
CASE
WHEN (SELECT Count(*)
FROM store_sales
WHERE ss_quantity BETWEEN 81 AND 100) > 23982 THEN
(SELECT Avg(ss_ext_list_price)
FROM store_sales
WHERE
ss_quantity BETWEEN 81 AND 100)
ELSE (SELECT Avg(ss_net_profit)
FROM store_sales
WHERE ss_quantity BETWEEN 81 AND 100)
END bucket5
FROM reason
WHERE r_reason_sk = 1;