-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathq61.sql
33 lines (33 loc) · 1.11 KB
/
q61.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
SELECT
promotions,
total,
cast(promotions AS DECIMAL(15, 4)) / cast(total AS DECIMAL(15, 4)) * 100
FROM
(SELECT sum(ss_ext_sales_price) promotions
FROM store_sales, store, promotion, date_dim, customer, customer_address, item
WHERE ss_sold_date_sk = d_date_sk
AND ss_store_sk = s_store_sk
AND ss_promo_sk = p_promo_sk
AND ss_customer_sk = c_customer_sk
AND ca_address_sk = c_current_addr_sk
AND ss_item_sk = i_item_sk
AND ca_gmt_offset = -5
AND i_category = 'Jewelry'
AND (p_channel_dmail = 'Y' OR p_channel_email = 'Y' OR p_channel_tv = 'Y')
AND s_gmt_offset = -5
AND d_year = 1998
AND d_moy = 11) promotional_sales,
(SELECT sum(ss_ext_sales_price) total
FROM store_sales, store, date_dim, customer, customer_address, item
WHERE ss_sold_date_sk = d_date_sk
AND ss_store_sk = s_store_sk
AND ss_customer_sk = c_customer_sk
AND ca_address_sk = c_current_addr_sk
AND ss_item_sk = i_item_sk
AND ca_gmt_offset = -5
AND i_category = 'Jewelry'
AND s_gmt_offset = -5
AND d_year = 1998
AND d_moy = 11) all_sales
ORDER BY promotions, total
LIMIT 100;