forked from agirish/tpcds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query50.sql
71 lines (71 loc) · 2.34 KB
/
query50.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
64
65
66
67
68
69
70
71
-- start query 50 in stream 0 using template query50.tpl
SELECT s_store_name,
s_company_id,
s_street_number,
s_street_name,
s_street_type,
s_suite_number,
s_city,
s_county,
s_state,
s_zip,
Sum(CASE
WHEN ( sr_returned_date_sk - ss_sold_date_sk <= 30 ) THEN 1
ELSE 0
END) AS `30 days`,
Sum(CASE
WHEN ( sr_returned_date_sk - ss_sold_date_sk > 30 )
AND ( sr_returned_date_sk - ss_sold_date_sk <= 60 )
THEN 1
ELSE 0
END) AS `31-60 days`,
Sum(CASE
WHEN ( sr_returned_date_sk - ss_sold_date_sk > 60 )
AND ( sr_returned_date_sk - ss_sold_date_sk <= 90 )
THEN 1
ELSE 0
END) AS `61-90 days`,
Sum(CASE
WHEN ( sr_returned_date_sk - ss_sold_date_sk > 90 )
AND ( sr_returned_date_sk - ss_sold_date_sk <= 120 )
THEN 1
ELSE 0
END) AS `91-120 days`,
Sum(CASE
WHEN ( sr_returned_date_sk - ss_sold_date_sk > 120 ) THEN 1
ELSE 0
END) AS `>120 days`
FROM store_sales,
store_returns,
store,
date_dim d1,
date_dim d2
WHERE d2.d_year = 2002
AND d2.d_moy = 9
AND ss_ticket_number = sr_ticket_number
AND ss_item_sk = sr_item_sk
AND ss_sold_date_sk = d1.d_date_sk
AND sr_returned_date_sk = d2.d_date_sk
AND ss_customer_sk = sr_customer_sk
AND ss_store_sk = s_store_sk
GROUP BY s_store_name,
s_company_id,
s_street_number,
s_street_name,
s_street_type,
s_suite_number,
s_city,
s_county,
s_state,
s_zip
ORDER BY s_store_name,
s_company_id,
s_street_number,
s_street_name,
s_street_type,
s_suite_number,
s_city,
s_county,
s_state,
s_zip
LIMIT 100;