Manage SQL views
Manage SQL views
Creating the SQL View
CREATE VIEW customer_stats AS
SELECT customers.id,
customers.email,
count(orders.*) AS nb_orders,
sum(products.price) AS amount_spent,
customers.created_at,
customers.updated_at
FROM customers
JOIN orders ON customers.id = orders.customer_id
JOIN products ON orders.product_id = products.id
GROUP BY customers.id;Adding the model
Managing the view

Last updated
Was this helpful?