From 802ae19187baf54a94b43a13bdf5947d83a3214f Mon Sep 17 00:00:00 2001 From: Karleen Richards Date: Mon, 22 May 2023 12:16:56 +0100 Subject: [PATCH] completed e-commerce - week 2 --- Big-Spender/readme.md | 11 +++++++--- E-Commerce/readme.md | 48 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index dc6cf9a2..3a3c5b9c 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -48,12 +48,14 @@ You are working with Claire and Farnoosh, who are trying to complete a missing r **You:** Absolutely. Here's the SQL query you need: ```sql -INSERT YOUR QUERY HERE +select * from spends +where amount > 30000 and amount < 31000; ``` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? **You:** Does case matter? +Yes, case does matter. **Claire:** I don't know. What do you meant? @@ -68,7 +70,10 @@ INSERT YOUR QUERY HERE **You:** Then here's the query for that: ```sql -INSERT YOUR QUERY HERE + +select * from spends +where lower(description) like lower('%Fee%'); + ``` **Farnoosh:** Hi, it's me again. It turns out we also need the transactions that have the expense area of 'Better Hospital Food'. Can you help us with that one? @@ -76,7 +81,7 @@ INSERT YOUR QUERY HERE **You:** No worries. Here's the query for that: ```sql -INSERT YOUR QUERY HERE + ``` **Claire:** Great, that's very helpful. How about the total amount spent for each month? diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index 37580cce..7809b658 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -46,13 +46,59 @@ 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 '%socks%'; +``` + - [ ] List all the products which cost more than 100 showing product id, name, unit price, and supplier id + +```sql +SELECT prod_id, product_name, unit_price FROM products INNER JOIN product_availability ON id = prod_id WHERE unit_price > 100; +``` + - [ ] List the 5 most expensive products + +```sql +SELECT product_name, unit_price FROM products INNER JOIN product_availability ON id = prod_id ORDER BY unit_price DESC; +``` + - [ ] 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 + +```sql +SELECT * FROM products p INNER JOIN product_availability pa ON pa.prod_id = p.id INNER JOIN suppliers s ON pa.supp_id = s.id WHERE s.country = 'United Kingdom'; +``` + +- [ done ] List all orders, including order items, from customer named Hope Crosby + +```sql +SELECT * FROM orders o +INNER JOIN customers c ON (c.id = o.customer_id) +INNER JOIN order_items oi ON (o.id = oi.order_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 + +```sql +SELECT 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 (oi.product_id = pa.prod_id) +INNER 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 +```sql +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 (c.id = o.customer_id) +INNER JOIN order_items oi ON (o.id = oi.order_id) +INNER JOIN product_availability pa ON (oi.product_id = pa.prod_id) +INNER JOIN suppliers s ON (pa.supp_id = s.id) +INNER JOIN products p ON (p.id = pa.prod_id) +``` + ## Acceptance Criteria - [ ] The `cyf_ecommerce` database is imported and set up correctly