From cc56adf01734a9a75c78ad97e0a03d053da9a6ca Mon Sep 17 00:00:00 2001 From: FrenchFry36 Date: Fri, 11 Apr 2025 15:25:31 +0200 Subject: [PATCH] e-commerce exercise done --- E-Commerce/cyf_ecommerce.sql | 13 +++++++++++++ E-Commerce/readme.md | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/E-Commerce/cyf_ecommerce.sql b/E-Commerce/cyf_ecommerce.sql index eff65118..28c8fbea 100644 --- a/E-Commerce/cyf_ecommerce.sql +++ b/E-Commerce/cyf_ecommerce.sql @@ -477,3 +477,16 @@ VALUES (19, 1, 5); +select * from products where product_name like '%socks%'; + +SELECT a.id, a.product_name, b.supp_id, b.unit_price FROM products a INNER JOIN product_availability b ON a.id = b.prod_id WHERE b.unit_price > 100; + +SELECT a.id, a.product_name, b.supp_id, b.unit_price FROM products a INNER JOIN product_availability b ON a.id = b.prod_id ORDER BY b.unit_price DESC LIMIT 5; + +SELECT a.product_name, b.supplier_name FROM products a INNER JOIN product_availability c ON a.id = c.prod_id INNER JOIN suppliers b ON c.supp_id = b.id WHERE b.country = 'United Kingdom'; + +select a.*, b.* from orders a INNER JOIN order_items b ON a.id = b.order_id INNER JOIN customers c ON a.customer_id = c.id WHERE c.name = 'Hope Crosby'; + +select distinct p.product_name, pa.unit_price, oi.quantity from products p INNER JOIN product_availability pa ON p.id = pa.prod_id INNER JOIN order_items oi ON p.id = oi.product_id INNER JOIN orders o ON oi.order_id = o.id WHERE o.order_reference = 'ORD006'; + +select c.name AS customer_name, o.order_reference, o.order_date, p.product_name, s.supplier_name, oi.quantity from customers c INNER JOIN orders o ON c.id = o.customer_id INNER JOIN order_items oi ON o.id = oi.order_id INNER JOIN products p ON oi.product_id = p.id INNER JOIN product_availability pa ON p.id = pa.prod_id INNER JOIN suppliers s ON pa.supp_id = s.id; \ No newline at end of file diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index 37580cce..d7b76b69 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -45,17 +45,17 @@ 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 +- [V] List all the products whose name contains the word "socks" +- [V] List all the products which cost more than 100 showing product id, name, unit price, and supplier id +- [V] List the 5 most expensive products +- [V] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name +- [V] List all orders, including order items, from customer named Hope Crosby +- [V] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity +- [V] 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 ## Acceptance Criteria -- [ ] The `cyf_ecommerce` database is imported and set up correctly -- [ ] The database schema is drawn correctly to visualize relationships between tables -- [ ] The SQL queries retrieve the correct data according to the tasks listed above -- [ ] The pull request with the answers to the tasks is opened on the `main` branch of the `E-Commerce` repository +- [v] The `cyf_ecommerce` database is imported and set up correctly +- [v] The database schema is drawn correctly to visualize relationships between tables +- [v] The SQL queries retrieve the correct data according to the tasks listed above +- [v] The pull request with the answers to the tasks is opened on the `main` branch of the `E-Commerce` repository