Skip to content

NW6 | Fathi Kahin | Module-DataBases | Big_Spender | week 2 #160

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

fhkahin
Copy link

@fhkahin fhkahin commented May 17, 2024

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

@fhkahin fhkahin changed the title Read me updated, All queries are written in SQL NW6 | Fathi Kahin | Module-DataBases | Big_Spender | week 2 May 17, 2024
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.

Good work overall and good understanding of queries, however there's opportunity to master more postgresql operators.

@@ -48,7 +48,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
INSERT YOUR QUERY HERE
SELECT amount

Choose a reason for hiding this comment

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

Almost there! Requirement is to find out the transactions between 30,000 and 31,000, not just the amount. How will your select statement be amended to get the desired result?

INSERT YOUR QUERY HERE
SELECT *
FROM spends
WHERE description LIKE '%fee%';

Choose a reason for hiding this comment

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

Good approach and query is on the right track. However, based on the scenario question, "fee" might be inconsistently capitalised in the data. To avoid missing results, the WHERE clause should account for this. What postgresql operator allows for case insensitive matching? Compare your results

SELECT sp.date, sp.description, expense.expense_area
FROM spends sp
JOIN expense_areas expense ON (sp.expense_area_id = expense.id)
WHERE expense.expense_area LIKE '%Better Hospital Food%';

Choose a reason for hiding this comment

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

Good use of joins!

@@ -92,15 +99,19 @@ CREATE YOUR QUERY HERE
**You:** Sure thing. Here's the query for that:

```sql
INSERT YOUR QUERY HERE
SELECT to_char(date,'YYYY-MM') AS month, sum(amount)

Choose a reason for hiding this comment

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

Good job with the date formatting. well done

```

**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 sp.amount, sup.supplier

Choose a reason for hiding this comment

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

The question is for the total amount spent by each supplier. Which operator missing here is needed to get the desired result?

@@ -124,7 +138,8 @@ 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 (expense_type_id, expense_area_id, supplier_id, date, transaction_no, supplier_inv_no, description, amount)
VALUES (7, 18, 16, '2021-08-19', 38104091, '3780119655', 'Computer Hardware Dell', 32000);

Copy link

@sayoiscool sayoiscool Jun 15, 2024

Choose a reason for hiding this comment

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

Good attempt here. The rows ' Dell', 'Hardware' and 'IT' are missing from other tables, what extra step is needed to have the rows populated where necessary? What effect will this change have on the 'id's inserted in spends table?

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.

2 participants