From bae2447823a25731d61d2b7981e56c48dca880e8 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 13:59:48 +0100 Subject: [PATCH 01/10] List all the products whose name contains the word "socks" --- E-Commerce/readme.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index 37580cce..173d825e 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -38,7 +38,7 @@ erDiagram id INT PK name VARCHAR(50) NOT NULL } - customers ||--o{ orders : places + customers ||--o{ orders : places} ``` ### Query Practice @@ -46,6 +46,13 @@ erDiagram Write SQL queries to complete the following tasks: - [ ] List all the products whose name contains the word "socks" + +```sql + select * from products where product_name like '%sock%'; + + -- producing all the names in product table containing 'sock' +``` + - [ ] 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 From a9e7acc60bb500ba66784c9a089590c541e6fa7c Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 14:27:07 +0100 Subject: [PATCH 02/10] List all the products which cost more than 100 showing product id, name, unit price, and supplier id --- E-Commerce/readme.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index 173d825e..f94ef154 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -45,7 +45,7 @@ erDiagram Write SQL queries to complete the following tasks: -- [ ] List all the products whose name contains the word "socks" +- [x] List all the products whose name contains the word "socks" ```sql select * from products where product_name like '%sock%'; @@ -54,6 +54,13 @@ Write SQL queries to complete the following tasks: ``` - [ ] List all the products which cost more than 100 showing product id, name, unit price, and supplier id + +```sql + select pv.prod_id , p.product_name ,pv.supp_id,sp.supplier_name , pv.unit_price from product_availability pv join products p on (pv.prod_id=p.id) join suppliers sp on(sp.id=pv.supp_id) where unit_price>100; + + -- the query shows the product id , its name , supplier id and supplier name , along side the unit_price . +``` + - [ ] 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 From e1fc8a57c580b731ea2ed59dd86143f43673f775 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 14:37:21 +0100 Subject: [PATCH 03/10] List the 5 most expensive products --- E-Commerce/readme.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index f94ef154..a92ef664 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -53,7 +53,7 @@ Write SQL queries to complete the following tasks: -- producing all the names in product table containing 'sock' ``` -- [ ] List all the products which cost more than 100 showing product id, name, unit price, and supplier id +- [x] List all the products which cost more than 100 showing product id, name, unit price, and supplier id ```sql select pv.prod_id , p.product_name ,pv.supp_id,sp.supplier_name , pv.unit_price from product_availability pv join products p on (pv.prod_id=p.id) join suppliers sp on(sp.id=pv.supp_id) where unit_price>100; @@ -62,6 +62,13 @@ Write SQL queries to complete the following tasks: ``` - [ ] List the 5 most expensive products + +```sql +select * from product_availability order by unit_price desc limit 5; +the query order unit_pric descending and limit results to first 5 items. + +``` + - [ ] 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 From 445957f742945bb84af421edaa5d2f6949bc2e59 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 14:50:30 +0100 Subject: [PATCH 04/10] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name --- E-Commerce/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index a92ef664..eb8eadb7 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -70,6 +70,12 @@ the query order unit_pric descending and limit results to first 5 items. ``` - [ ] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name + +```sql + select p.product_name ,sp.supplier_name from order_items o join products p on (o.product_id=p.id) join suppliers sp on (o.supplier_id=sp.id) where sp.country='United Kingdom'; + -- Query retrieves rpoduct name and supp name from other tables using join +``` + - [ ] 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 From 4832378da2d8b1ccdba8e09c80377b79b9bba331 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 15:00:20 +0100 Subject: [PATCH 05/10] minor fixes --- E-Commerce/readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index eb8eadb7..f6ab2d48 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -61,15 +61,15 @@ Write SQL queries to complete the following tasks: -- the query shows the product id , its name , supplier id and supplier name , along side the unit_price . ``` -- [ ] List the 5 most expensive products +- [x] List the 5 most expensive products ```sql select * from product_availability order by unit_price desc limit 5; -the query order unit_pric descending and limit results to first 5 items. +-- the query order unit_pric descending and limit results to first 5 items. ``` -- [ ] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name +- [x] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name ```sql select p.product_name ,sp.supplier_name from order_items o join products p on (o.product_id=p.id) join suppliers sp on (o.supplier_id=sp.id) where sp.country='United Kingdom'; From 7e06fc825694f97b65c3960aa8c42cb0d7ca6edc Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 21:37:44 +0100 Subject: [PATCH 06/10] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity --- E-Commerce/readme.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index f6ab2d48..dcdc2bf7 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -77,7 +77,12 @@ select * from product_availability order by unit_price desc limit 5; ``` - [ ] 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 +- [x] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity + +```sql + select pr.product_name, oi.quantity,sp.supplier_name from orders o join order_items oi on (o.id=oi.order_id) join suppliers sp on (oi.supplier_id=sp.id) join products pr on (pr.id=oi.product_id) where 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 ## Acceptance Criteria From a3180d6ed3b4e4a9b0221f133ff9cc6d0d3d6129 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 21:53:40 +0100 Subject: [PATCH 07/10] List all orders, including order items, from customer named Hope Crosby --- E-Commerce/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index dcdc2bf7..473c36d1 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -77,6 +77,12 @@ select * from product_availability order by unit_price desc limit 5; ``` - [ ] List all orders, including order items, from customer named Hope Crosby + +```sql + select o.id,o.order_date,o.order_reference ,cu.name,pr.product_name from orders o join order_items oi on (o.id=oi.order_id) join customers cu on (o.customer_id=cu.id) join products pr on (oi.product_id=pr.id) where name='Hope Crosby'; + -- This query connects 4 tabels but it returns only order id order_date , order_reference , customer name and product name. +``` + - [x] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity ```sql From 8075d8789bad2eaabccc03566f1897cabcdded83 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 21:55:07 +0100 Subject: [PATCH 08/10] List all orders, including order items, from customer named Hope Crosby --- E-Commerce/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index 473c36d1..d203bfe4 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -76,7 +76,7 @@ select * from product_availability order by unit_price desc limit 5; -- Query retrieves rpoduct name and supp name from other tables using join ``` -- [ ] List all orders, including order items, from customer named Hope Crosby +- [x] List all orders, including order items, from customer named Hope Crosby ```sql select o.id,o.order_date,o.order_reference ,cu.name,pr.product_name from orders o join order_items oi on (o.id=oi.order_id) join customers cu on (o.customer_id=cu.id) join products pr on (oi.product_id=pr.id) where name='Hope Crosby'; From 1e61474114e9aed20774f372fa4e87a113716e15 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 22:05:02 +0100 Subject: [PATCH 09/10] 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 --- E-Commerce/readme.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index d203bfe4..cdb1da80 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -89,7 +89,11 @@ select * from product_availability order by unit_price desc limit 5; select pr.product_name, oi.quantity,sp.supplier_name from orders o join order_items oi on (o.id=oi.order_id) join suppliers sp on (oi.supplier_id=sp.id) join products pr on (pr.id=oi.product_id) where 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 +- [x] 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 + +```sql + select cu.name , o.order_reference , o.order_date,pr.product_name , sp.supplier_name , oi.quantity from orders o join customers cu on (o.customer_id=cu.id) join order_items oi on(oi.order_id=o.id) join products pr on(oi.product_id=pr.id) join suppliers sp on (oi.supplier_id=sp.id) ; +``` ## Acceptance Criteria From 47a063632a26155a1f22ebdc012d561a4bf82144 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 6 May 2024 22:06:06 +0100 Subject: [PATCH 10/10] final completion checks --- E-Commerce/readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index cdb1da80..8e174dcc 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -97,7 +97,7 @@ select * from product_availability order by unit_price desc limit 5; ## 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 +- [x] The `cyf_ecommerce` database is imported and set up correctly +- [x] The database schema is drawn correctly to visualize relationships between tables +- [x] The SQL queries retrieve the correct data according to the tasks listed above +- [x] The pull request with the answers to the tasks is opened on the `main` branch of the `E-Commerce` repository