From dbfe3177cd9ba19356c4b850377f3422055a8031 Mon Sep 17 00:00:00 2001 From: SalehOmar-Y Date: Sun, 14 Dec 2025 21:51:40 +0000 Subject: [PATCH 1/4] Add SQL queries for transaction retrieval and data insertion in README --- Big-Spender/readme.md | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index dc6cf9a..b14a4e7 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -48,7 +48,8 @@ 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 transaction_no Between 30000 And 31000; ``` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? @@ -68,7 +69,7 @@ INSERT YOUR QUERY HERE **You:** Then here's the query for that: ```sql -INSERT YOUR QUERY HERE +Select * from spends where description ILike '%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,15 +77,22 @@ INSERT YOUR QUERY HERE **You:** No worries. Here's the query for that: ```sql -INSERT YOUR QUERY HERE -``` +Select transaction_no, expense_area +from spends +Join expense_areas +On spends.expense_area_id = expense_areas.id +Where expense_area ILIKE '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 -CREATE YOUR QUERY HERE +Select DATE_TRUNC('month', spends.date) AS month +, SUM(spends.amount) AS total_spend +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? @@ -92,7 +100,10 @@ CREATE YOUR QUERY HERE **You:** Sure thing. Here's the query for that: ```sql -INSERT YOUR QUERY HERE +Select supplier_id, SUM(amount) AS total_spent +From spends +Group by supplier_id +Order by total_spent desc; ``` **Farnoosh:** Oh, how do I know who these suppliers are? There's only numbers here. @@ -100,7 +111,10 @@ INSERT YOUR QUERY HERE **You:** Whoops! I gave you ids to key the totals, but let me give you names instead. ```sql -INSERT YOUR QUERY HERE +Select description, SUM(amount) AS total_spent +From spends +Group by description +Order by total_spent desc; ``` **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)? @@ -112,7 +126,12 @@ INSERT YOUR QUERY HERE **You:** Then you need an extra clause. Here's the query: ```sql -CREATE YOUR QUERY HERE +Select date_trunc('day', spends.date) As day, + Sum(amount) As total_spent +From spends +Where date IN ('2021-03-01', '2021-04-01') +Group by day +Order by day; ``` **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? @@ -124,8 +143,12 @@ 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 -INSERT YOUR QUERIES HERE - +Insert into spends + (amount, date, transaction_no, supplier_inv_no, description, expense_type_id, expense_area_id) + Values + (32000, '2021-08-19', 38104091, 3780119655, 'Dell', + (SELECT id FROM expense_types WHERE expense_type = 'Hardware'), + (SELECT id FROM expense_areas WHERE expense_area = 'IT')); ``` **Claire:** Great, that's everything we need. Thanks for your help. From 5b16c2a5d8d3b7020641905feeade3b84a2de335 Mon Sep 17 00:00:00 2001 From: SalehOmar-Y Date: Tue, 16 Dec 2025 13:33:09 +0000 Subject: [PATCH 2/4] Fix SQL query in README to filter by amount instead of transaction number --- Big-Spender/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index b14a4e7..173c2d0 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -49,7 +49,7 @@ You are working with Claire and Farnoosh, who are trying to complete a missing r ```sql Select * from spends -Where transaction_no Between 30000 And 31000; +Where amount Between 30000 And 31000; ``` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? From ccc6968a82c572ac9a590bd649fa9dc95af9b91d Mon Sep 17 00:00:00 2001 From: SalehOmar-Y Date: Tue, 16 Dec 2025 14:11:30 +0000 Subject: [PATCH 3/4] Fix SQL queries in README for correct syntax and clarity --- Big-Spender/readme.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 173c2d0..1373608 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -49,7 +49,7 @@ You are working with Claire and Farnoosh, who are trying to complete a missing r ```sql Select * from spends -Where amount Between 30000 And 31000; +Where am Between 30000 And 31000; ``` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? @@ -77,7 +77,7 @@ Select * from spends where description ILike '%fee%'; **You:** No worries. Here's the query for that: ```sql -Select transaction_no, expense_area +Select * from spends Join expense_areas On spends.expense_area_id = expense_areas.id @@ -89,7 +89,7 @@ Where expense_area ILIKE 'Better Hospital Food'; **You:** You can get that by using the GROUP BY clause. Here's the query: ```sql -Select DATE_TRUNC('month', spends.date) AS month +Select Extract(Month from spends.date) AS month , SUM(spends.amount) AS total_spend From spends Group by month; @@ -100,7 +100,7 @@ Group by month; **You:** Sure thing. Here's the query for that: ```sql -Select supplier_id, SUM(amount) AS total_spent +Select SUM(amount) AS total_spent From spends Group by supplier_id Order by total_spent desc; @@ -111,9 +111,11 @@ Order by total_spent desc; **You:** Whoops! I gave you ids to key the totals, but let me give you names instead. ```sql -Select description, SUM(amount) AS total_spent -From spends -Group by description +Select s.supplier As supplier_name, + SUM(sp.amount) AS total_spent +From suppliers s +Join spends sp On sp.supplier_id = s.id +Group by s.supplier Order by total_spent desc; ``` From fc5ce52b7510ab83f46f1b3a8f7c4c3d65a55275 Mon Sep 17 00:00:00 2001 From: SalehOmar-Y Date: Wed, 17 Dec 2025 01:31:56 +0000 Subject: [PATCH 4/4] Fix SQL query in README to use 'amount' instead of 'am' --- Big-Spender/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 1373608..7afd77d 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -49,7 +49,7 @@ You are working with Claire and Farnoosh, who are trying to complete a missing r ```sql Select * from spends -Where am Between 30000 And 31000; +Where amount Between 30000 And 31000; ``` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description?