forked from agirish/tpcds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query56.sql
68 lines (68 loc) · 2.35 KB
/
query56.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
-- start query 56 in stream 0 using template query56.tpl
WITH ss
AS (SELECT i_item_id,
Sum(ss_ext_sales_price) total_sales
FROM store_sales,
date_dim,
customer_address,
item
WHERE i_item_id IN (SELECT i_item_id
FROM item
WHERE i_color IN ( 'firebrick', 'rosy', 'white' )
)
AND ss_item_sk = i_item_sk
AND ss_sold_date_sk = d_date_sk
AND d_year = 1998
AND d_moy = 3
AND ss_addr_sk = ca_address_sk
AND ca_gmt_offset = -6
GROUP BY i_item_id),
cs
AS (SELECT i_item_id,
Sum(cs_ext_sales_price) total_sales
FROM catalog_sales,
date_dim,
customer_address,
item
WHERE i_item_id IN (SELECT i_item_id
FROM item
WHERE i_color IN ( 'firebrick', 'rosy', 'white' )
)
AND cs_item_sk = i_item_sk
AND cs_sold_date_sk = d_date_sk
AND d_year = 1998
AND d_moy = 3
AND cs_bill_addr_sk = ca_address_sk
AND ca_gmt_offset = -6
GROUP BY i_item_id),
ws
AS (SELECT i_item_id,
Sum(ws_ext_sales_price) total_sales
FROM web_sales,
date_dim,
customer_address,
item
WHERE i_item_id IN (SELECT i_item_id
FROM item
WHERE i_color IN ( 'firebrick', 'rosy', 'white' )
)
AND ws_item_sk = i_item_sk
AND ws_sold_date_sk = d_date_sk
AND d_year = 1998
AND d_moy = 3
AND ws_bill_addr_sk = ca_address_sk
AND ca_gmt_offset = -6
GROUP BY i_item_id)
SELECT i_item_id,
Sum(total_sales) total_sales
FROM (SELECT *
FROM ss
UNION ALL
SELECT *
FROM cs
UNION ALL
SELECT *
FROM ws) tmp1
GROUP BY i_item_id
ORDER BY total_sales
LIMIT 100;