-
Notifications
You must be signed in to change notification settings - Fork 28.4k
/
q9.sql
executable file
·48 lines (48 loc) · 1.53 KB
/
q9.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
SELECT
CASE WHEN (SELECT count(*)
FROM store_sales
WHERE ss_quantity BETWEEN 1 AND 20) > 62316685
THEN (SELECT avg(ss_ext_discount_amt)
FROM store_sales
WHERE ss_quantity BETWEEN 1 AND 20)
ELSE (SELECT avg(ss_net_paid)
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) > 19045798
THEN (SELECT avg(ss_ext_discount_amt)
FROM store_sales
WHERE ss_quantity BETWEEN 21 AND 40)
ELSE (SELECT avg(ss_net_paid)
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) > 365541424
THEN (SELECT avg(ss_ext_discount_amt)
FROM store_sales
WHERE ss_quantity BETWEEN 41 AND 60)
ELSE (SELECT avg(ss_net_paid)
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) > 216357808
THEN (SELECT avg(ss_ext_discount_amt)
FROM store_sales
WHERE ss_quantity BETWEEN 61 AND 80)
ELSE (SELECT avg(ss_net_paid)
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) > 184483884
THEN (SELECT avg(ss_ext_discount_amt)
FROM store_sales
WHERE ss_quantity BETWEEN 81 AND 100)
ELSE (SELECT avg(ss_net_paid)
FROM store_sales
WHERE ss_quantity BETWEEN 81 AND 100) END bucket5
FROM reason
WHERE r_reason_sk = 1