-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-3.sql
More file actions
41 lines (29 loc) · 895 Bytes
/
5-3.sql
File metadata and controls
41 lines (29 loc) · 895 Bytes
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
-- Find tables in the product list
SELECT DISTINCT order_items.name
FROM customers c
LATERAL VIEW EXPLODE(c.orders) o AS ords
LATERAL VIEW EXPLODE(ords.items) i AS order_items
-- WHERE lower(order_items.name) like '%table%'
LIMIT 1000;
-- Gather some stats about orders of table products
SELECT
c.name AS CustName,
addy.city as CustCity,
addy.state as CustState,
addy.zip_code as CustZip,
count(distinct ords.order_id) as OrderCount,
sum(order_items.price * order_items.qty) as OrderAmount
FROM customers c
-- get address information
LATERAL VIEW EXPLODE(c.addresses) a AS a_key, addy
-- get order details
LATERAL VIEW EXPLODE(c.orders) o AS ords
LATERAL VIEW EXPLODE(ords.items) i AS order_items
--filter results
WHERE
lower(order_items.name) like '%table%'
GROUP BY
c.name,
addy.city,
addy.state,
addy.zip_code