Skip to content

London 9 _Sana Asaf _Module-Databases_Week 2#32

Closed
SanaAsaf wants to merge 1 commit intoCodeYourFuture:mainfrom
SanaAsaf:main
Closed

London 9 _Sana Asaf _Module-Databases_Week 2#32
SanaAsaf wants to merge 1 commit intoCodeYourFuture:mainfrom
SanaAsaf:main

Conversation

@SanaAsaf
Copy link

ER- Diagram
(https://github.com/CodeYourFuture/Module-Databases/assets/85436780/5d1025c6-450e-4168-91c6-36cce474c210)

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.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link

@Alexander-Rennie Alexander-Rennie left a comment

Choose a reason for hiding this comment

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

Great answers (some minor observations included below)

- [ ] List all the products in the order ORD006. The result should only contain the columns product_name, unit_price, and quantity
- [ ] List all the products with their supplier for all orders of all customers. The result should only contain the columns name (from customer), order_reference, order_date, product_name, supplier_name, and quantity
- [*] List all the products whose name contains the word "socks"
SELECT * FROM products WHERE product_name LIKE ‘%socks%’;

Choose a reason for hiding this comment

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

CORRECT

SELECT prod_id, product_name, unit_price, supp_id
FROM product_availability pa INNER JOIN products p on (pa.prod_id=p.id)
INNER JOIN suppliers s on (pa.supp_id=s.id)
WHERE unit_price > 100;

Choose a reason for hiding this comment

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

CORRECT - Whilst this is not wrong, there is no need to join in the suppliers table, as you are only returning no details from it (only the supp_id which is in product_availability)

WHERE unit_price > 100;

- [*] List the 5 most expensive products
select product_name , unit_price FROM product_availability pa INNER JOIN products p on (pa.prod_id=p.id) by unit_price desc Limit 5;

Choose a reason for hiding this comment

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

CORRECT

- [*] List all the products sold by suppliers based in the United Kingdom. The result should only contain the columns product_name and supplier_name
SELECT product_name , supplier_name
FROM product_availability pa INNER JOIN products p on (pa.prod_id=p.id)
INNER JOIN suppliers s on (pa.supp_id=s.id) where s.country='United Kingdom';

Choose a reason for hiding this comment

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

CORRECT

SELECT order_id,product_id,supplier_id,quantity
FROM order_items oi INNER JOIN orders o ON (oi.order_id=o.id)
INNER JOIN customers c ON (o.customer_id=c.id)
where c.name = 'Hope Crosby';

Choose a reason for hiding this comment

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

CORRECT

FROM order_items oi INNER JOIN orders o ON (oi.order_id=o.id)
INNER JOIN products p ON (p.id=oi.product_id)
INNER JOIN product_availability pa ON (p.id=pa.prod_id)
WHERE o.order_reference = 'ORD006';

Choose a reason for hiding this comment

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

CORRECT

INNER JOIN order_items oi ON (oi.order_id=o.id)
INNER JOIN products p ON (p.id=oi.product_id)
INNER JOIN product_availability pa ON (p.id=pa.prod_id)
INNER JOIN suppliers s ON (pa.supp_id=s.id);

Choose a reason for hiding this comment

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

CORRECT - Whilst this is not wrong, there is no need to join in the product_availability table, as you are returning no details from it, and could link to suppliers via oi.supplier_id

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