Skip to content
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 number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
72 changes: 72 additions & 0 deletions cyf_ecommerce
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
order_id | order_reference | order_date | total
----------+-----------------+------------+-------
1 | ORD001 | 2019-06-01 | 18
1 | ORD001 | 2019-06-01 | 25
2 | ORD002 | 2019-07-15 | 32
2 | ORD002 | 2019-07-15 | 10
3 | ORD003 | 2019-07-11 | 40
3 | ORD003 | 2019-07-11 | 40
(6 rows)

order_id | order_reference | order_date | total
----------+-----------------+------------+-------
1 | ORD001 | 2019-06-01 | 18
1 | ORD001 | 2019-06-01 | 25
2 | ORD002 | 2019-07-15 | 32
2 | ORD002 | 2019-07-15 | 10
3 | ORD003 | 2019-07-11 | 40
3 | ORD003 | 2019-07-11 | 40
(6 rows)

order_id | order_reference | order_date | total
----------+-----------------+------------+-------
1 | ORD001 | 2019-06-01 | 18
1 | ORD001 | 2019-06-01 | 25
2 | ORD002 | 2019-07-15 | 32
2 | ORD002 | 2019-07-15 | 10
3 | ORD003 | 2019-07-11 | 40
3 | ORD003 | 2019-07-11 | 40
(6 rows)

order_id | product_name | order_reference | order_date | total
----------+-------------------------+-----------------+------------+-------
1 | Tee Shirt Olympic Games | ORD001 | 2019-06-01 | 18
1 | Super warm socks | ORD001 | 2019-06-01 | 25
2 | Super warm socks | ORD002 | 2019-07-15 | 32
2 | Le Petit Prince | ORD002 | 2019-07-15 | 10
3 | Coffee Cup | ORD003 | 2019-07-11 | 40
3 | Ball | ORD003 | 2019-07-11 | 40
(6 rows)

order_id | order_reference | order_date | total
----------+-----------------+------------+-------
1 | ORD001 | 2019-06-01 | 18
1 | ORD001 | 2019-06-01 | 25
2 | ORD002 | 2019-07-15 | 32
2 | ORD002 | 2019-07-15 | 10
3 | ORD003 | 2019-07-11 | 40
3 | ORD003 | 2019-07-11 | 40
(6 rows)

List of relations
Schema | Name | Type | Owner
--------+----------------------+-------+-------
public | customers | table | admin
public | order_items | table | admin
public | orders | table | admin
public | product_availability | table | admin
public | products | table | admin
public | suppliers | table | admin
(6 rows)

List of relations
Schema | Name | Type | Owner
--------+----------------------+-------+-------
public | customers | table | admin
public | order_items | table | admin
public | orders | table | admin
public | product_availability | table | admin
public | products | table | admin
public | suppliers | table | admin
(6 rows)

17 changes: 13 additions & 4 deletions week-1/mandatory/2-classes-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

## Submission

Below you will find a set of tasks for you to complete to consolidate and extend your learning from this week. You will find it beneficial to complete the reading tasks before attempting some of these.
Below you will find a set of tasks for you to complete to consolidate and extend your learning from this week. You will find it beneficial to complete the reading tasks before attempting some of these.

To submit this homework write the correct commands for each question here:

```sql


1. select * from rooms where rate > 100;
2. select * from reservations where (checkin_date >= '2020-09-01' and checkin_date <='2020-09-30') and checkout_date - checkin_date < 3;
3. select * from customers where city like 'M%';
4. insert into room_types values('PENTHOUSE','185.00');
5. insert into rooms (room_no, rate, room_type) values(501,(select def_rate from room_types where room_type = 'PENTHOUSE'),'PENTHOUSE'),(502,(select def_rate from room_types where room_type = 'PENTHOUSE'),'PENTHOUSE');
6. insert into rooms (room_no, rate, room_type) values(503,143.00,'PREMIER PLUS');
7. select all from reservations where checkin_date >= '2020-08-01' and checkin_date <= '2020-08-31'; / select count(id) from reservations where checkin_date >= '2020-08-01' and checkin_date <= '2020-08-31';
8. select sum(checkout_date - checkin_date) from reservations where room_no between 200 and 299;
9. select sum(total),avg(total) from invoices where total > 300;
10. select sum(case when room_no between 100 and 199 then checkout_date - checkin_date end) as first_floor, sum(case when room_no between 200 and 299 then checkout_date - checkin_date end) as second_floor, sum(case when room_no between 300 and 399 then checkout_date - checkin_date end) as third_floor, sum(case when room_no between 400 and 499 then checkout_date - checkin_date end) as fourth_floor from reservations;
```

When you have finished all of the questions - open a pull request with your answers to the `Databases-Homework` repository.
Expand All @@ -18,6 +26,7 @@ When you have finished all of the questions - open a pull request with your answ
If you haven't completed all the exercises from this lesson then do that first.

### Tasks

1. Which rooms have a rate of more than 100.00?
2. List the reservations that have a checkin date this month and are for more than three nights.
3. List all customers from cities that begin with the letter 'M'.
Expand All @@ -33,4 +42,4 @@ Using what you can learn about aggregate functions in the w3schools SQL classes
7. The hotel manager wishes to know how many rooms were occupied any time during the previous month - find that information.
8. Get the total number of nights that customers stayed in rooms on the second floor (rooms 201 - 299).
9. How many invoices are for more than £300.00 and what is their grand total and average amount?
10. Bonus Question: list the number of nights stay for each floor of the hotel (floor no is the hundreds part of room number, e.g. room **3**12 is on floor **3**)
10. Bonus Question: list the number of nights stay for each floor of the hotel (floor no is the hundreds part of room number, e.g. room **3**12 is on floor **3**)
Binary file added week-2/mandatory/2-ecommerce-db/ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 18 additions & 3 deletions week-2/mandatory/2-ecommerce-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@ 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 * from customers where country = 'United States';
2. select * from customers order by name;
3. select * from products where product_name like '%socks%';
4. select a.prod_id, p.product_name,a.supp_id,a.unit_price from product_availability a join products p on p.id = a.prod_id where a.unit_price > 100;
5. select * from product_availability order by unit_price DESC limit 5;
6. select p.product_name,a.unit_price,s.supplier_name from product_availability a join products p on p.id = a.prod_id join suppliers s on a.supp_id = s.id;
7. select p.product_name,s.supplier_name from product_availability a join products p on p.id = a.prod_id join suppliers s on a.supp_id = s.id where s.country = 'United Kingdom';
8-a. select o.id as Order_ID,o.order_reference, o.order_date, a.unit_price * i.quantity as total from order_items i join orders o on o.id=i.order_id join product_availability a on (i.product_id = a.prod_id and i.supplier_id = a.supp_id) where o.customer_id = 1;
8-b. select o.id as Order_ID,p.product_name, o.order_reference, o.order_date, a.unit_price * i.quantity as total from order_items i join orders o on o.id=i.order_id join product_availability a on (i.product_id = a.prod_id and i.supplier_id = a.supp_id) join products p on p.id = a.prod_id where o.customer_id = 1;
8-c. select o.id as Order_ID, o.order_reference, o.order_date, sum(a.unit_price * i.quantity) as total from order_items i join orders o on o.id=i.order_id join product_availability a on (i.product_id = a.prod_id and i.supplier_id = a.supp_id) where o.customer_id = 1 group by o.id; (after mentor explanation)
9. select o.id as Order_ID, p.product_name from orders o join order_items i on o.id = i.order_id join customers c on c.id = o.customer_id join products p on p.id = i.product_id where c.name = 'Hope Crosby';
10. select p.product_name, a.unit_price, i.quantity from order_items i join orders o on o.id=i.order_id join product_availability a on (i.product_id = a.prod_id and i.supplier_id = a.supp_id) join products p on p.id = a.prod_id where o.order_reference = 'ORD006';
11. select c.name, o.order_reference, o.order_date, p.product_name, s.supplier_name, i.quantity from order_items i join product_availability a on (i.product_id = a.prod_id and i.supplier_id = a.supp_id) join orders o on o.id = i.order_id join customers c on o.customer_id = c.id join products p on a.prod_id = p.id join suppliers s on a.supp_id = s.id;
12. select distinct c.name from order_items i join orders o on i.order_id = o.id join customers c on c.id = o.customer_id join suppliers s on i.supplier_id = s.id where s.country = 'China';
13. select c.name, o.order_reference, o.order_date, sum(i.quantity * a.unit_price) as total from orders o join customers c on o.customer_id = c.id join order_items i on i.order_id = o.id join product_availability a on (i.product_id = a.prod_id and i.supplier_id = a.supp_id) group by c.name, o.order_reference, o.order_date order by total DESC;

```

Expand Down Expand Up @@ -41,10 +57,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