Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 215
NW5 Manchester - Doris Siu - SQL - Week 2#186
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| node_modules | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,7 +7,83 @@ In this homework, you are going to work with an ecommerce database. In this data | ||
| Below you will find a set of tasks for you to complete to set up a database for an e-commerce app. | ||
| To submit this homework write the correct commands for each question here: | ||
| ```sql | ||
| 1. select name, address from customers where country = 'United States'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using uppercase for your SQL commands can make it easier to read :) | ||
| 2. select * from customers order by name; | ||
| 3. select * from products where product_name ilike 'socks%' or product_name ilike '%socks' or product_name ilike '%socks%'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can just use | ||
| 4. select pa.prod_id, p.product_name, pa.unit_price, pa.supp_id | ||
| from product_availability pa | ||
| join products p | ||
| on (pa.prod_id = p.id) | ||
| where pa.unit_price >100; | ||
| 5. select * from product_availability order by unit_price desc limit 5; | ||
| 6. select p.product_name, pa.unit_price, s.supplier_name from products p join product_availability pa on (p.id=pa.prod_id) join suppliers s on (s.id=pa.supp_id); | ||
| 7. select p.product_name, s.supplier_name from products p join product_availability pa on (p.id=pa.prod_id) join suppliers s on (s.id=pa.supp_id) where s.country = 'United Kingdom'; | ||
| 8. select oi.order_id, o.order_reference, o.order_date, (oi.quantity * pa.unit_price) as total_cost | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like how you're using | ||
| from orders o | ||
| join order_items oi | ||
| on (o.id = oi.order_id) | ||
| join product_availability pa | ||
| on (oi.product_id = pa.prod_id); | ||
| 9. select o.order_date, o.order_reference, oi.order_id, oi.quantity, p.product_name as order_items | ||
| from customers c | ||
| join orders o | ||
| on (c.id = o.customer_id) | ||
| join order_items oi | ||
| on (o.id = oi.order_id) | ||
| join product_availability pa | ||
| on (oi.product_id = pa.prod_id) | ||
| join products p | ||
| on (pa.prod_id = p.id) | ||
| where c.name = 'Hope Crosby'; | ||
| 10. select p.product_name, pa.unit_price, oi.quantity | ||
| from customers c | ||
| join orders o | ||
| on (c.id = o.customer_id) | ||
| join order_items oi | ||
| on (o.id = oi.order_id) | ||
| join product_availability pa | ||
| on (oi.product_id = pa.prod_id) | ||
| join products p | ||
| on (pa.prod_id = p.id) | ||
| where o.order_reference = 'ORD006'; | ||
| 11. select c.name, o.order_date, o.order_reference, p.product_name, s.supplier_name, oi.quantity | ||
| from customers c | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. splitting your clauses over new lines make it easier to follow, nice job :) | ||
| join orders o | ||
| on (c.id = o.customer_id) | ||
| join order_items oi | ||
| on (o.id = oi.order_id) | ||
| join product_availability pa | ||
| on (oi.product_id = pa.prod_id) | ||
| join products p | ||
| on (pa.prod_id = p.id) | ||
| join suppliers s on (s.id = pa.supp_id); | ||
| 12. select c.name | ||
| from customers c | ||
| join orders o | ||
| on (c.id = o.customer_id) | ||
| join order_items oi | ||
| on (o.id = oi.order_id) | ||
| join product_availability pa | ||
| on (oi.product_id = pa.prod_id) | ||
| join products p | ||
| on (pa.prod_id = p.id) | ||
| join suppliers s on (s.id = pa.supp_id) where s.country = 'China'; | ||
| 13.select c.name, o.order_reference, o.order_date, p.product_name, (oi.quantity *pa.unit_price) as total | ||
| from customers c | ||
| join orders o | ||
| on (c.id = o.customer_id) | ||
| join order_items oi | ||
| on (o.id = oi.order_id) | ||
| join product_availability pa | ||
| on (oi.product_id = pa.prod_id) | ||
| join products p | ||
| on (pa.prod_id = p.id) | ||
| join suppliers s on (s.id = pa.supp_id)order by total desc; | ||
| ``` | ||
| @@ -41,10 +117,9 @@ Once you understand the database that you are going to work with, solve the foll | ||
| 5. Retrieve the 5 most expensive products | ||
| 6. Retrieve all the products with their corresponding suppliers. The result should only contain the columns `product_name`, `unit_price` and `supplier_name` | ||
| 7. Retrieve all the products sold by suppliers based in the United Kingdom. The result should only contain the columns `product_name` and `supplier_name`. | ||
| 8. Retrieve all orders, including order items, from customer ID `1`. Include order id, reference, date and total cost (calculated as quantity * unit price). | ||
| 8. Retrieve all orders, including order items, from customer ID `1`. Include order id, reference, date and total cost (calculated as quantity \* unit price). | ||
| 9. Retrieve all orders, including order items, from customer named `Hope Crosby` | ||
| 10. Retrieve all the products in the order `ORD006`. The result should only contain the columns `product_name`, `unit_price` and `quantity`. | ||
| 11. Retrieve 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`. | ||
| 12. Retrieve the names of all customers who bought a product from a supplier based in China. | ||
| 13. List all orders giving customer name, order reference, order date and order total amount (quantity * unit price) in descending order of total. | ||
| 13. List all orders giving customer name, order reference, order date and order total amount (quantity \* unit price) in descending order of total. | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you remembered to add node_modules to your .gitignore file, good job