Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
node_modules

Copy link
Copy Markdown

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

81 changes: 78 additions & 3 deletions 2-exercises/task.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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%';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you can just use %socks% here

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you're using AS total_cost here

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;





```
Expand DownExpand Up@@ -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.
Loading