From 50eaf4ff68ab7b6b4b1997a484039fd0aa24fca7 Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 21:19:17 +0100 Subject: [PATCH 1/8] quereing spends between 30 to 31 in spends table --- Big-Spender/readme.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index dc6cf9a2..42c45d1a 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -47,8 +47,13 @@ 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 BETWEEN 30000 AND 31000; ``` **Claire:** That's great, thanks. Hey, what about transactions that include the word 'fee' in their description? From 6f41b197d58ece56da49b7b7029fea9fd3dd310a Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 21:34:29 +0100 Subject: [PATCH 2/8] query to return word fee in description --- Big-Spender/readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 42c45d1a..38b8c38f 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -80,8 +80,11 @@ INSERT YOUR QUERY HERE **You:** No worries. Here's the query for that: + + ```sql INSERT YOUR QUERY HERE +select * from spends where lower(description) like '%fee%'; ``` **Claire:** Great, that's very helpful. How about the total amount spent for each month? From 5d701f4c5548eb65d3a44cb086d1f6a7464565dc Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 21:47:07 +0100 Subject: [PATCH 3/8] add up amounts and group them according months spends --- Big-Spender/readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 38b8c38f..ab998427 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -91,8 +91,11 @@ select * from spends where lower(description) like '%fee%'; **You:** You can get that by using the GROUP BY clause. Here's the query: + + ```sql CREATE YOUR QUERY HERE +select sum(amount) , to_char(date,'yyyy-mm') as month 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? From ce4a2d6d6d57fc8d3cdc377a74b165f23ce4fe2c Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 22:19:29 +0100 Subject: [PATCH 4/8] amount spent on suppliers with id --- Big-Spender/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index ab998427..799da88a 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -102,8 +102,12 @@ select sum(amount) , to_char(date,'yyyy-mm') as month from spends group by month **You:** Sure thing. Here's the query for that: + + ```sql INSERT YOUR QUERY HERE +select supplier_id , sum(amount) as total from spends group by supplier_id order by supplier_id ; + ``` **Farnoosh:** Oh, how do I know who these suppliers are? There's only numbers here. From 3bf94c14b044c87dd3000f357edbf9e19433da14 Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 22:28:03 +0100 Subject: [PATCH 5/8] adding supplier name the the spent amount on them by join to supp table --- Big-Spender/readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 799da88a..16ac1263 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -114,8 +114,13 @@ select supplier_id , sum(amount) as total from spends group by supplier_id order **You:** Whoops! I gave you ids to key the totals, but let me give you names instead. + + ```sql INSERT YOUR QUERY HERE +select sd.supplier_id ,spl.supplier ,sum(sd.amount) as total from spends sd join suppliers spl on (spl.id=sd.supplier_id) group by spl.supplier, sd.supplier_id +order by spl.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)? From 31f45baa10d9f851f3d48ae8a49ffb2b63e9ac82 Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 22:43:01 +0100 Subject: [PATCH 6/8] add up for amount for 1st of march and 1st of April --- Big-Spender/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 16ac1263..6c894922 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -131,8 +131,12 @@ order by spl.supplier **You:** Then you need an extra clause. Here's the query: + + ```sql CREATE YOUR QUERY HERE +select date , sum(amount) from spends where (date='2021-03-01') or (date='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? From 556c02658a92e7b30c894477e6eac8b1de606708 Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 23:22:07 +0100 Subject: [PATCH 7/8] inserting a row to the spends#ing table , last exercise --- Big-Spender/readme.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index 6c894922..320440bf 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -149,6 +149,20 @@ select date , sum(amount) from spends where (date='2021-03-01') or (date='2021-0 ```sql INSERT YOUR QUERIES HERE +-- first we add a new supplier 'Dell' into suppliers: +Insert into suppliers(supplier) values('DELL'); + +-- adding Hardware to expense_types: +insert into expense_types(expense_type) values('Hardware'); + +-- adding IT to expense_areas as well: +insert into expense_areas(expense_area) values('IT'); + +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',32000.00) +; +-- After Insert this data and did some query on the table I realised another field with name 'Hardware Purch' is in the expense_types +-- also there wasn't an IT feild for expense areas so i created it, I hope I've understood the questions correctly . ``` From 8cc3b0e8418ea92290a0b17e1adb0c5d3d2108a9 Mon Sep 17 00:00:00 2001 From: karimi Date: Sat, 27 Apr 2024 23:22:37 +0100 Subject: [PATCH 8/8] inserting a row to the spends#ing table , last exercise --- 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 320440bf..e5a429b7 100644 --- a/Big-Spender/readme.md +++ b/Big-Spender/readme.md @@ -162,7 +162,7 @@ INSERT INTO spends(expense_type_id,expense_area_id , supplier_id , date , transa values(42,46,66,'2021-08-19',38104091,3780119655,'Computer Hardware Dell',32000.00) ; -- After Insert this data and did some query on the table I realised another field with name 'Hardware Purch' is in the expense_types --- also there wasn't an IT feild for expense areas so i created it, I hope I've understood the questions correctly . +-- also there wasn't an IT feild for expense areas so i created it, I hope I understood the questions correctly . ```