From c22702e6eace1b966b36ac41e8386eee6e31efb4 Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sat, 23 Sep 2023 12:32:24 +0100 Subject: [PATCH 1/3] Completed Big-Spender --- Big-Spender/readme.md | 66 +++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index dc6cf9a2..ff744fb5 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -47,9 +47,10 @@ 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 +````sql INSERT YOUR QUERY HERE -``` +select * from spends where amount between 30000 and 31000; +```` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? @@ -67,42 +68,54 @@ INSERT YOUR QUERY HERE **You:** Then here's the query for that: -```sql +````sql INSERT YOUR QUERY HERE -``` +SELECT * FROM spends WHERE LOWER(description) LIKE '%fee%' OR LOWER(description) LIKE '%fees%' + **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? **You:** No worries. Here's the query for that: -```sql +````sql INSERT YOUR QUERY HERE -``` +select * from spends join expense_areas +on(spends.expense_area_id= expense_areas.id) +where expense_areas.expense_area='Better Hospital Food'; + +```` **Claire:** Great, that's very helpful. How about the total amount spent for each month? **You:** You can get that by using the GROUP BY clause. Here's the query: -```sql +````sql CREATE YOUR QUERY HERE -``` +``` SELECT date, SUM(amount) As amount FROM spends GROUP BY date ``` +```` **Farnoosh:** Thanks, that's really useful. We also need to know the total amount spent on each supplier. Can you help us with that? **You:** Sure thing. Here's the query for that: -```sql +````sql INSERT YOUR QUERY HERE -``` +``` SELECT supplier_id, SUM(amount) As amount FROM spends GROUP BY supplier_id`` +```` **Farnoosh:** Oh, how do I know who these suppliers are? There's only numbers here. **You:** Whoops! I gave you ids to key the totals, but let me give you names instead. -```sql +````sql INSERT YOUR QUERY HERE -``` +``` SELECT suppliers.id, suppliers.supplier, SUM(amount) as total_per_month +FROM suppliers +FULL OUTER JOIN spends ON suppliers.id = spends.supplier_id +GROUP BY suppliers.id +```` +```` **Claire:** Thanks, that's really helpful. I can't quite figure out...what is the total amount spent on each of these two dates (1st March 2021 and 1st April 2021)? **You:** I think you can use the BETWEEN clause to get the total amount spent on a range of dates, just like we used earlier. @@ -113,7 +126,13 @@ INSERT YOUR QUERY HERE ```sql CREATE YOUR QUERY HERE -``` + +SELECT date, SUM(amount) as total_per_month +FROM spends +WHERE date BETWEEN '2021-03-01' AND '2021-04-01' +GROUP BY date + +```` **Farnoosh:** Fantastic. One last thing, looks like we missed something. Can we add a new transaction to the spends table with a description of 'Computer Hardware Dell' and an amount of £32,000? @@ -123,10 +142,22 @@ CREATE YOUR QUERY HERE **You:** Sure thing. To confirm, the date is August 19, 2021, the transaction number is 38104091, the supplier invoice number is 3780119655, the supplier is 'Dell', the expense type is 'Hardware' and the expense area is 'IT'. Here's the query for that: -```sql +````sql INSERT YOUR QUERIES HERE - -``` +``` INSERT INTO expense_types(expense_type) VALUES('Hardware')``` +``` INSERT INTO expense_areas(expense_area) VALUES('IT')``` +``` INSERT INTO suppliers(supplier) VALUES('Dell')``` + +``` INSERT INTO spends (expense_type_id, expense_area_id, supplier_id, date, transaction_no, supplier_inv_no, description, amount) +VALUES (42, + 46, + 66, + '2021-08-19', + 38104091, + '3780119655', + 'Computer Hardware Dell', + 320000); +```` **Claire:** Great, that's everything we need. Thanks for your help. @@ -136,5 +167,4 @@ INSERT YOUR QUERIES HERE - [ ] All user stories are satisfied - [ ] All queries are written in SQL -- [ ] All queries are correct and I have tested them in the database -- [ ] I have opened a pull request with my answers written directly into this README.md file +- [ ] All queries are correct and I have tested them in the database \ No newline at end of file From fde8cf60a9ee5391534f4c663f3c2e88b2c19d7d Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sat, 23 Sep 2023 12:32:49 +0100 Subject: [PATCH 2/3] Completed E-commerce --- E-Commerce/readme.md | 80 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/E-Commerce/readme.md b/E-Commerce/readme.md index 37580cce..025dafd1 100644 --- a/E-Commerce/readme.md +++ b/E-Commerce/readme.md @@ -46,12 +46,90 @@ erDiagram Write SQL queries to complete the following tasks: - [ ] List all the products whose name contains the word "socks" + +SELECT product_name from products WHERE product_name ILIKE '%socks%'; + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + + - [ ] List all the products which cost more than 100 showing product id, name, unit price, and supplier id +SELECT p.id, pa.supp_id AS supplier_id, p.product_name, pa.unit_price +FROM products AS p +INNER JOIN product_availability AS pa +ON pa.prod_id = p.id +WHERE pa.unit_price > 100; + + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + - [ ] List the 5 most expensive products + +SELECT p.id ,p.product_name +FROM products AS p INNER JOIN product_availability AS pa ON (pa.prod_id = p.id) +ORDER BY 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 p.product_name, s.supplier_name +FROM products AS p +INNER JOIN product_availability AS pa ON p.id = pa.prod_id +INNER JOIN suppliers AS s ON pa.supp_id = s.id +WHERE s.country = 'United Kingdom'; + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + - [ ] List all orders, including order items, from customer named Hope Crosby + +SELECT + o.id AS order_id, + o.order_date, + o.order_reference, + oi.product_id, + oi.supplier_id, + oi.quantity +FROM orders o +INNER JOIN order_items oi ON o.id = oi.order_id +INNER JOIN customers c ON o.customer_id = c.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 -- [ ] 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 + p.product_name, + pa.unit_price, + oi.quantity +FROM products AS p +INNER JOIN product_availability AS pa ON p.id = pa.prod_id +INNER JOIN order_items AS oi ON p.id = oi.product_id +INNER JOIN orders AS 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 + ord.order_reference, + ord.order_date, + p.product_name, + s.supplier_name, + oi.quantity +FROM products AS p +INNER JOIN order_items AS oi ON p.id = oi.product_id +INNER JOIN orders AS ord ON oi.order_id = ord.id +INNER JOIN suppliers AS s ON oi.supplier_id = s.id; + + + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` ## Acceptance Criteria From e03f75031ee38c149335b13329dd6e5ddff13352 Mon Sep 17 00:00:00 2001 From: Yuliya110692 <122671093+Yuliya110692@users.noreply.github.com> Date: Sat, 23 Sep 2023 12:36:05 +0100 Subject: [PATCH 3/3] Updated Big-Spender --- Big-Spender/readme.md | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index ff744fb5..559a6b27 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -49,8 +49,13 @@ You are working with Claire and Farnoosh, who are trying to complete a missing r ````sql INSERT YOUR QUERY HERE +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + select * from spends where amount between 30000 and 31000; -```` + + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? @@ -70,8 +75,12 @@ select * from spends where amount between 30000 and 31000; ````sql INSERT YOUR QUERY HERE +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + SELECT * FROM spends WHERE LOWER(description) LIKE '%fee%' OR LOWER(description) LIKE '%fees%' +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + **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? @@ -79,11 +88,14 @@ SELECT * FROM spends WHERE LOWER(description) LIKE '%fee%' OR LOWER(description) ````sql INSERT YOUR QUERY HERE +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + select * from spends join expense_areas on(spends.expense_area_id= expense_areas.id) where expense_areas.expense_area='Better Hospital Food'; -```` +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + **Claire:** Great, that's very helpful. How about the total amount spent for each month? @@ -91,8 +103,12 @@ where expense_areas.expense_area='Better Hospital Food'; ````sql CREATE YOUR QUERY HERE -``` SELECT date, SUM(amount) As amount FROM spends GROUP BY date ``` -```` +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + +SELECT date, SUM(amount) As amount FROM spends GROUP BY date + + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` **Farnoosh:** Thanks, that's really useful. We also need to know the total amount spent on each supplier. Can you help us with that? @@ -100,8 +116,11 @@ CREATE YOUR QUERY HERE ````sql INSERT YOUR QUERY HERE -``` SELECT supplier_id, SUM(amount) As amount FROM spends GROUP BY supplier_id`` -```` +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + +SELECT supplier_id, SUM(amount) As amount FROM spends GROUP BY supplier_id`` + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` **Farnoosh:** Oh, how do I know who these suppliers are? There's only numbers here. @@ -109,13 +128,16 @@ INSERT YOUR QUERY HERE ````sql INSERT YOUR QUERY HERE -``` SELECT suppliers.id, suppliers.supplier, SUM(amount) as total_per_month +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + + SELECT suppliers.id, suppliers.supplier, SUM(amount) as total_per_month FROM suppliers FULL OUTER JOIN spends ON suppliers.id = spends.supplier_id GROUP BY suppliers.id -```` -```` + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + **Claire:** Thanks, that's really helpful. I can't quite figure out...what is the total amount spent on each of these two dates (1st March 2021 and 1st April 2021)? **You:** I think you can use the BETWEEN clause to get the total amount spent on a range of dates, just like we used earlier. @@ -126,13 +148,15 @@ GROUP BY suppliers.id ```sql CREATE YOUR QUERY HERE +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` SELECT date, SUM(amount) as total_per_month FROM spends WHERE date BETWEEN '2021-03-01' AND '2021-04-01' GROUP BY date -```` +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` + **Farnoosh:** Fantastic. One last thing, looks like we missed something. Can we add a new transaction to the spends table with a description of 'Computer Hardware Dell' and an amount of £32,000? @@ -144,11 +168,13 @@ GROUP BY date ````sql INSERT YOUR QUERIES HERE -``` INSERT INTO expense_types(expense_type) VALUES('Hardware')``` -``` INSERT INTO expense_areas(expense_area) VALUES('IT')``` -``` INSERT INTO suppliers(supplier) VALUES('Dell')``` +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` -``` INSERT INTO spends (expense_type_id, expense_area_id, supplier_id, date, transaction_no, supplier_inv_no, description, amount) +INSERT INTO expense_types(expense_type) VALUES('Hardware') +INSERT INTO expense_areas(expense_area) VALUES('IT') +INSERT INTO suppliers(supplier) VALUES('Dell') + +INSERT INTO spends (expense_type_id, expense_area_id, supplier_id, date, transaction_no, supplier_inv_no, description, amount) VALUES (42, 46, 66, @@ -157,7 +183,8 @@ VALUES (42, '3780119655', 'Computer Hardware Dell', 320000); -```` + +`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` **Claire:** Great, that's everything we need. Thanks for your help.