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