1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
 
 
-- Get email survey opt-in values for all customers
SELECT
c.id,
c.name,
c.email_preferences.categories.surveys
FROM customers c;
 
 
 
-- Select customers for a given shipping ZIP Code
SELECT
customers.id,
customers.name
FROM customers
WHERE customers.addresses['shipping'].zip_code = '76710';
 
 
 
-- Compute total amount per order for all customers
 
 
 
 
 
 
 
 
 
 
 
 
7 days ago
 
Sample: Customers
-- Get email survey opt-in values for all customers 
SELECT 
c.id
c.name
c.email_preferences.categories.surveys 
FROM customers c
 
 
 
-- Select customers for a given shipping ZIP Code 
SELECT 
customers.id
customers.name 
FROM customers 
WHERE customers.addresses['shipping'].zip_code = '76710'
 
 
 
-- Compute total amount per order for all customers 
SELECT 
c.id AS customer_id
c.name AS customer_name
ords.order_id AS order_id
SUM(order_items.price * order_items.qty) AS total_amount 
FROM 
customers c 
LATERAL VIEW EXPLODE(c.orders) o AS ords 
LATERAL VIEW EXPLODE(ords.items) i AS order_items 
GROUP BY c.id, c.name, ords.order_id