Skip to content

NW6 | Sabella Fisseha | Module-DataBases | Big_Spender | week 2 #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sabella-8
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@Sabella-8
Copy link
Author

Copy link

@sayoiscool sayoiscool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work overall! Good attention to detail with the table insertions and good understanding of some postgresql operators. However a few more query revisions needed, as described in comments.

```

````
select * from spends where description ilike '%FeE%'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work taking capitalisations into consideration with 'ilike'. note you don't have to mix cases in the word, e.g '%FeE%' can simply be written as '%fee%'. ILIKE already handles the case insensitive matching


SELECT spends.*, expense_areas.expense_area
FROM spends
INNER JOIN expense_areas ON expense_areas.id = spends.expense_area_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of joins!


**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', date)::date AS month, SUM(amount) AS total

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work with the date format


SELECT SUM(spends.amount) AS total_amount
FROM spends
INNER JOIN suppliers ON suppliers.id = spends.supplier_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with the joins! However, two columns are expected in the results. What additional information from the suppliers table should be included in the SELECT statement?


SELECT date, SUM(amount) AS total_amount
FROM spends
WHERE date BETWEEN '2021-03-01' AND '2021-04-01'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good attempt. Note that total amounts for only those two dates are required, and not every date inbetween. Which operator will allow for multiple distinct values to be specified in your WHERE statement?

insert into expense_types (expense_type) values ('Hardware');
select id from expense_areas where expense_area = 'IT';
insert into expense_areas (expense_area) values ('IT');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great attention to detail! The 'Hardware', 'Dell', and 'IT' rows were missing from the other tables, and you've done well by adding the necessary insert statements to populate them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants