From cf75f7a85a74ee1556da65722c3ab38089dffc47 Mon Sep 17 00:00:00 2001
From: Damilola Odumosu
Date: Fri, 8 Sep 2023 20:37:24 +0100
Subject: [PATCH 1/2] big-spender
---
Big-Spender/readme.md | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md
index dc6cf9a2..78fa5331 100644
--- a/Big-Spender/readme.md
+++ b/Big-Spender/readme.md
@@ -29,7 +29,7 @@ psql big-spender
## User Stories:
- As a data analyst, I want to retrieve specific transaction records that meet a certain criteria, so that I can generate insights and reports based on the data.
-- As a finance manager, I want to know the total amount spent on a specific month, so that I can compare it with our budget and plan accordingly.
+- As a fi\qnance manager, I want to know the total amount spent on a specific month, so that I can compare it with our budget and plan accordingly.
- As a data analyst, I want to filter transactions by a specific keyword, so that I can retrieve records that are relevant to my analysis.
- As a finance manager, I want to add a missing transaction to the database, so that it correctly reflects our latest expenses for our report.
@@ -47,9 +47,9 @@ 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 amount 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?
@@ -69,7 +69,7 @@ INSERT YOUR QUERY HERE
```sql
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?
@@ -77,7 +77,11 @@ INSERT YOUR QUERY HERE
```sql
INSERT YOUR QUERY HERE
-```
+```select * from spends s
+join expense_areas e
+on (s.expense_area_id = e.id)
+where e.expense_area = 'Better Hospital Food';
+````
**Claire:** Great, that's very helpful. How about the total amount spent for each month?
From 3698810ade773143056889d09bb7b0088653a422 Mon Sep 17 00:00:00 2001
From: Damilola Odumosu
Date: Tue, 19 Sep 2023 18:43:56 +0100
Subject: [PATCH 2/2] big-spender completed
---
Big-Spender/readme.md | 86 +++++++++++++++++++++++++++++++++----------
1 file changed, 67 insertions(+), 19 deletions(-)
diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md
index 78fa5331..b259318d 100644
--- a/Big-Spender/readme.md
+++ b/Big-Spender/readme.md
@@ -47,9 +47,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 amount FROM spends WHERE amount BETWEEN 30000 AND 31000;
+`````sql
+
+SELECT amount
+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,45 +72,63 @@ INSERT YOUR QUERY HERE
**You:** Then here's the query for that:
-```sql
-INSERT YOUR QUERY HERE
-```select * from spends where description like '%Fee%';
+````sql
+
+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 * from spends s
+````sql
+select *
+from spends s
join expense_areas e
on (s.expense_area_id = e.id)
where e.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
-CREATE YOUR QUERY HERE
+````sql
+select date, sum(amount)
+as total_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
-INSERT YOUR QUERY HERE
+````sql
+
+select supplier_id, sum(amount)
+as supplier_total
+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
-INSERT YOUR QUERY HERE
-```
+````sql
+select supplier, sum(amount) as supplier_total
+from spends
+join suppliers
+on (suppliers.id = spends.supplier_id)
+group by supplier
+;
+
+`````
**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)?
@@ -116,7 +139,11 @@ INSERT YOUR QUERY HERE
**You:** Then you need an extra clause. Here's the query:
```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?
@@ -128,7 +155,28 @@ 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 suppliers (supplier)
+VALUES ('Dell');
+
+INSERT INTO expense_types (expense_type)
+VALUES ('Hardware');
+
+INSERT INTO expense_areas (expense_area)
+VALUES ('IT');
+
+INSERT INTO spends
+(transaction_no,
+supplier_inv_no,
+description,
+amount,
+date)
+
+VALUES (38104091,
+3780119655,
+'Computer Hardware Dell',
+32000,
+ '2021-08-19');
+
```