From 9d29409d2433ec7297ac438de1acbb9c683a7ae7 Mon Sep 17 00:00:00 2001 From: bahador Date: Mon, 6 May 2024 02:14:30 +0100 Subject: [PATCH 1/2] added query for description --- Big-Spender/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index dc6cf9a2..0ae77376 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -47,7 +47,7 @@ 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 +```SELECT * FROM spends WHERE amount BETWEEN 30000 AND 31000; INSERT YOUR QUERY HERE ``` @@ -67,7 +67,7 @@ INSERT YOUR QUERY HERE **You:** Then here's the query for that: -```sql +```SELECT * FROM spends WHEREQ description LIKE '%fee%'; INSERT YOUR QUERY HERE ``` From 09859015b0c223b9020d5a002dd5ed2739b89e6a Mon Sep 17 00:00:00 2001 From: bahador Date: Mon, 6 May 2024 15:33:56 +0100 Subject: [PATCH 2/2] completed Big Spender --- Big-Spender/readme.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 0ae77376..6a87fb2d 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -67,16 +67,18 @@ INSERT YOUR QUERY HERE **You:** Then here's the query for that: -```SELECT * FROM spends WHEREQ description LIKE '%fee%'; +``` INSERT YOUR QUERY HERE +SELECT * FROM spends WHERE description LIKE '%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? **You:** No worries. Here's the query for that: -```sql +``` INSERT YOUR QUERY HERE +SELECT sp.date, sp.description, expense.expense_area FROM spends sp JOIN expense_areas expense ON (sp.expense_area_id = expense.id) WHERE expense.expense_area LIKE '%Better Hospital Food%'; ``` **Claire:** Great, that's very helpful. How about the total amount spent for each month? @@ -85,6 +87,7 @@ INSERT YOUR QUERY HERE ```sql CREATE YOUR QUERY HERE + SELECT to_char(date,'YYYY-MM') AS months, sum(amount) FROM spends GROUP BY month; ``` **Farnoosh:** Thanks, that's really useful. We also need to know the total amount spent on each supplier. Can you help us with that? @@ -93,6 +96,7 @@ CREATE YOUR QUERY HERE ```sql INSERT YOUR QUERY HERE +SELECT sp.amount FROM spends sp JOIN suppliers sup ON (sp.supplier_id = sup.id); ``` **Farnoosh:** Oh, how do I know who these suppliers are? There's only numbers here. @@ -101,6 +105,7 @@ INSERT YOUR QUERY HERE ```sql INSERT YOUR QUERY HERE +SELECT sp.amount, sup.supplier FROM spends sp JOIN suppliers sup ON (sp.supplier_id = sup.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)? @@ -113,6 +118,10 @@ INSERT YOUR QUERY HERE ```sql CREATE YOUR QUERY HERE + +SELECT date,SUM(amount) FROM spends +WHERE date in ('2021-03-01', '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? @@ -126,11 +135,23 @@ CREATE YOUR QUERY HERE ```sql INSERT YOUR QUERIES HERE + BEGIN; + +INSERT INTO spends (date, transaction_no, supplier_inv_no) VALUES ('2021-08-19', 38104091, 3780119655); +INSERT INTO expense_types (expense_type) VALUES ('Hardware'); +INSERT INTO expense_areas (expense_area) VALUES ('IT'); +INSERT INTO suppliers (supplier) VALUES ('Dell'); + +COMMIT; + +BEGIN; + ``` **Claire:** Great, that's everything we need. Thanks for your help. **You:** No problem, glad I could help you out. +bye bye Claire ! ## Acceptance Criteria