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
46 changes: 39 additions & 7 deletions E-Commerce/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,45 @@ erDiagram

Write SQL queries to complete the following tasks:

- [ ] List all the products whose name contains the word "socks"
- [ ] List all the products which cost more than 100 showing product id, name, unit price, and supplier id
- [ ] List the 5 most expensive products
- [ ] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name
- [ ] List all orders, including order items, from customer named Hope Crosby
- [ ] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity
- [ ] 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
- [*] List all the products whose name contains the word "socks"
SELECT * FROM products WHERE product_name LIKE ‘%socks%’;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT


- [*] List all the products which cost more than 100 showing product id, name, unit price, and supplier id
SELECT prod_id, product_name, unit_price, supp_id
FROM product_availability pa INNER JOIN products p on (pa.prod_id=p.id)
INNER JOIN suppliers s on (pa.supp_id=s.id)
WHERE unit_price > 100;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT - Whilst this is not wrong, there is no need to join in the suppliers table, as you are only returning no details from it (only the supp_id which is in product_availability)


- [*] List the 5 most expensive products
select product_name , unit_price FROM product_availability pa INNER JOIN products p on (pa.prod_id=p.id) by unit_price desc Limit 5;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT


- [*] 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 product_name , supplier_name
FROM product_availability pa INNER JOIN products p on (pa.prod_id=p.id)
INNER JOIN suppliers s on (pa.supp_id=s.id) where s.country='United Kingdom';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT



- [*] List all orders, including order items, from customer named Hope Crosby
SELECT order_id,product_id,supplier_id,quantity
FROM order_items oi INNER JOIN orders o ON (oi.order_id=o.id)
INNER JOIN customers c ON (o.customer_id=c.id)
where c.name = 'Hope Crosby';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT


- [*] 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 order_items oi INNER JOIN orders o ON (oi.order_id=o.id)
INNER JOIN products p ON (p.id=oi.product_id)
INNER JOIN product_availability pa ON (p.id=pa.prod_id)
WHERE o.order_reference = 'ORD006';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT


- [*] 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,o.order_reference,o.order_date,p.product_name,s.supplier_name,oi.quantity
FROM customers c INNER JOIN orders o ON (o.customer_id=c.id)
INNER JOIN order_items oi ON (oi.order_id=o.id)
INNER JOIN products p ON (p.id=oi.product_id)
INNER JOIN product_availability pa ON (p.id=pa.prod_id)
INNER JOIN suppliers s ON (pa.supp_id=s.id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORRECT - Whilst this is not wrong, there is no need to join in the product_availability table, as you are returning no details from it, and could link to suppliers via oi.supplier_id



## Acceptance Criteria

Expand Down