Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion E-Commerce/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In this project, you will work with an e-commerce database. The database has pro
To prepare your environment, open a terminal and create a new database called `cyf_ecommerce`:

```sql
createdb cyf_ecommerce
createdb cyf_ecommerce;
```

Import the file [`cyf_ecommerce.sql`](./cyf_ecommerce.sql) in your newly created database:
Expand Down Expand Up @@ -46,12 +46,52 @@ erDiagram
Write SQL queries to complete the following tasks:

- [ ] List all the products whose name contains the word "socks"
select \*
from products
where product_name like '%socks%';

- [ ] List all the products which cost more than 100 showing product id, name, unit price, and supplier id
SELECT products.id,products.product_name,product_availability.unit_price,product_availability.supp_id
FROM products
INNER JOIN order_items ON order_items.product_id = products.id
INNER JOIN product_availability ON product_availability.prod_id = products.id
WHERE product_availability.unit_price > 100;

- [ ] List the 5 most expensive products
SELECT \* FROM product_availability
ORDER BY unit_price DESC
LIMIT 5;

- [ ] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name

SELECT p.product_name, s.supplier_name
FROM products p
JOIN order_items ON p.id = order_items.product_id
JOIN suppliers s ON s.id = order_items.supplier_id
WHERE s.country = 'United Kingdom';

- [ ] List all orders, including order items, from customer named Hope Crosby
SELECT \*
FROM orders o
JOIN order_items ON o.id = order_items.order_id
JOIN customers c ON o.customer_id = c.id
WHERE c.name = 'Hope Crosby';

- [ ] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity
SELECT p.product_name, pa.unit_price, oi.quantity
FROM orders as o
INNER JOIN order_items oi ON o.id = oi.order_id
INNER JOIN products as p ON oi.product_id = p.id
INNER JOIN product_availability as pa ON p.id = pa.prod_id
WHERE o.order_reference = 'ORD006';

- [ ] List all the products with their supplier for all orders of all customers. The result should only contain the columns name (from customer), order_reference, order_date, product_name, supplier_name, and quantity
SELECT c.name AS customer_name, o.order_reference, o.order_date, p.product_name, s.supplier_name, oi.quantity
FROM customers c
JOIN orders o ON c.id = o.customer_id
JOIN order_items oi ON o.id = oi.order_id
JOIN products p ON oi.product_id = p.id
JOIN suppliers s ON oi.supplier_id = s.id;

## Acceptance Criteria

Expand Down