Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NW6 | Fathi Kahin | Module-Database | E-commerce | Week 3 #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fhkahin wants to merge 1 commit into CodeYourFuture:main
base: main
Choose a base branch
Loading
from fhkahin:E-Commerce
Open
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
55 changes: 55 additions & 0 deletions E-Commerce/readme.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,61 @@ Write SQL queries to complete the following tasks:
- [ ] 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

### Query Practice Answers

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 pr.id AS product_id, pr.product_name, pa.unit_price, s.id AS supplier_id
FROM product_availability pa
JOIN products pr ON pa.prod_id = pr.id
JOIN suppliers s ON pa.supp_id = s.id
WHERE pa.unit_price > 100;

List the 5 most expensive products
SELECT pr.id as product_id, pr.product_name,pa.unit_price
FROM product_availability pa
JOIN products pr ON pa.prod_id = pr.id
ORDER BY pa.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 pr.product_name, s.supplier_name
FROM suppliers s
JOIN product_availability pa ON pa.supp_id = s.id
JOIN products pr ON pr.id = pa.prod_id
WHERE s.country = 'United Kingdom';

List all orders, including order items, from customer named Hope Crosby
SELECT orders.* ,order_items.* from orders
JOIN customers on customers.id = orders.customer_id
JOIN order_items on order_items.order_id = orders.id
join product_availability pa on order_items.product_id = pa.prod_id
AND order_items.supplier_id = pa.supp_id
WHERE customers.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 pr.product_name,
pa.unit_price,
oi.quantity
FROM products pr
JOIN product_availability pa ON pr.id = pa.prod_id
JOIN order_items oi ON pr.id = oi.product_id
JOIN orders o ON o.id = oi.order_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, o.order_reference, o.order_date, pr.product_name, s.supplier_name, oi.quantity
from products pr
join product_availability pa on pr.id = pa.prod_id
join suppliers s on pa.supp_id = s.id
join order_items oi on oi.product_id = pa.prod_id
join orders o on o.id = oi.order_id
join customers c on c.id = o.customer_id;



## Acceptance Criteria

- [ ] The `cyf_ecommerce` database is imported and set up correctly
Expand Down

AltStyle によって変換されたページ (->オリジナル) /