diff --git a/Big-Spender/readme.md b/Big-Spender/readme.md index dc6cf9a2..e5a429b7 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? @@ -75,32 +80,47 @@ 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? **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? **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. **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)? @@ -111,8 +131,12 @@ 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='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? @@ -125,6 +149,20 @@ CREATE YOUR QUERY HERE ```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 understood the questions correctly . ```