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
19 changes: 15 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,23 @@

## 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 *, checkout_date - checkin_date as night from reservations where checkin_date between '2020-09-01'and '2020-09-30' and checkout_date - checkin_date > 3;
3. select * from customers where city like 'M%';
4. insert into room_types (room_type, def_rate)
values ('PENTHOUSE', '185');
5.insert into rooms (room_no, rate, room_type)
values ('501' ,185, 'PENTHOUSE'),('502' ,185, 'PENTHOUSE') ;
6. insert into rooms (room_no, rate, room_type)
values ('503' ,'143', 'PREMIER PLUS');
7. select count(room_no) from reservations where checkin_date <= '2020-08-31' and checkout_date > '2020-08-01'
8.select sum(checkout_date - checkin_date) from reservations where room_no between 201 and 299;
9. select count(*) as invoice_count, sum(total) as total_invoices, avg(total) as average_invoice from invoices where total > 300
```

When you have finished all of the questions - open a pull request with your answers to the `Databases-Homework` repository.
Expand All @@ -18,6 +28,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 +44,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**)
61 changes: 58 additions & 3 deletions week-2/mandatory/2-ecommerce-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,63 @@ 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 asc;
3. select * from products
where product_name like '%socks%';
4. select p.id, p.product_name, a.supp_id, a.unit_price from prodcuts p
join product_availability a on (a.prod_id = p.id) where unit_price > 100;
5. select p.id, p.product_name, a.supp_id, a.unit_price from products p
join product_availability a on a.prod_id = p.id
order by a.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 pa.supp_id = s.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 pa.supp_id = s.id where s.country = 'United Kingdom';

select p.product_name, s.supplier_name from products p
join product_availability pa on p.id = pa.prod_id
join suppliers s on pa.supp_id = s.id where upper(s.country) = 'UNITED KINGDOM';
8. select o.id, o.order_reference, o.order_date, oi.quantity*pa.unit_price as "total cost" from orders o
join customers c on o.customer_id = c.id
join order_items oi on o.id = oi.order_id
join product_availability pa on oi.product_id = pa.prod_id where c.id = 1;
9. select * from orders o
join order_items oi on o.id = oi.order_id where customer_id = (select id from customers where name = 'Hope Crosby');
select * from orders o
join order_items oi on o.id = oi.order_id
join customers c on o.customer_id = c.id where c.name = 'Hope Crosby';
10. select p.product_name, oi.quantity, pa.unit_price from products p
join product_availability pa on pa.prod_id = p.id
join order_items oi on oi.product_id = pa.prod_id
join orders o on o.id = oi.order_id where o.order_reference = 'ORD006';
11. select c.name, o.order_reference, o.order_date, p.product_name, s.supplier_name, oi.quantity from customers c
join orders o on c.id = o.customer_id
join order_items oi on oi.order_id = o.id
join products p on p.id = oi.product_id
join suppliers s on s.id = oi.supplier_id;
12. select distinct c.name, s.country from customers c
join orders o on c.id = o.customer_id
join order_items oi on oi.order_id = o.id
join suppliers s on oi.supplier_id = s.id
where s.country = 'China';
13. select c.name, o.order_reference, o.order_date, sum(oi.quantity*pa.unit_price) as "total amount" from orders o
join customers c on c.id = o.customer_id
join order_items oi on oi.order_id = o.id
join product_availability pa on pa.prod_id = oi.product_id
group by c.name, o.order_reference, o.order_date
order by "total amount" desc;







```
Expand Down Expand Up @@ -41,10 +97,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.
1 change: 1 addition & 0 deletions week-2/mandatory/3-api/cyf-ecommerce-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading