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
33 changes: 30 additions & 3 deletions week-1/mandatory/2-classes-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,37 @@

## 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.00;
2.select * from reservations where EXTRACT(MONTH from checkin_date)=EXTRACT(MONTH from current_date) and checkout_date-checkin_date>3;
3.select * from customers where name LIKE 'm%';
4.insert into room_types (room_type,def_rate) values ('PENTHOUSE',185.00);
5.insert into rooms (room_no,room_type,rate) values (502,'PENTHOUSE',185.00);
5.insert into rooms (room_no,room_type,rate) values (502,'PENTHOUSE',185.00);
to check what is inserted
select * from rooms order by room_no DESC LIMIT 10;
6. insert into rooms (room_no,rate,room_type) values(503 ,143.00,'PREMIER PLUS');
7. select COUNT(*) from reservations where EXTRACT(MONTH from checkin_date)=EXTRACT(MONTH from current_date -1);
8.select COUNT(checkout_date-checkin_date) from reservations where room_no BETWEEN 200 AND 300;
9. select COUNT(*) as total_no_of_invoices ,AVG(total) as average ,SUM(total) as total from invoices where total>300.00;
10.
first-floor
select sum(checkout_date-checkin_date) as nights_on_first_floor from reservations where room_no between 101 and 199;
second-floor
select sum(checkout_date-checkin_date) as nights_on_first_floor from reservations where room_no between 201 and 299;
third_floor
select sum(checkout_date-checkin_date) as nights_on_first_floor from reservations where room_no between 201 and 299;









```
Expand All @@ -18,6 +44,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 @@ -32,5 +59,5 @@ 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**)
9. How many invoices are for more than £300.00 and what is their grand total and 2average 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**)
3 changes: 3 additions & 0 deletions week-2/mandatory/2-ecommerce-db/cyf_ecommerce.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ CREATE TABLE order_items (
REFERENCES product_availability (prod_id, supp_id)
);




INSERT INTO customers (name, address, city, country) VALUES ('Guy Crawford','770-2839 Ligula Road','Paris','France');
INSERT INTO customers (name, address, city, country) VALUES ('Hope Crosby','P.O. Box 276, 4976 Sit Rd.','Steyr','United Kingdom');
INSERT INTO customers (name, address, city, country) VALUES ('Britanney Kirkland','P.O. Box 577, 5601 Sem, St.','Little Rock','United Kingdom');
Expand Down
56 changes: 53 additions & 3 deletions week-2/mandatory/2-ecommerce-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,60 @@ 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';
2.select name from customers order by name asc;
3.select * from products where product_name ilike '%sock%';
4.select p.product_name ,pa.prod_id ,pa.unit_price,pa.supp_id
from products p join product_availability pa
on (p.id=pa.prod_id)
where pa.unit_price>100;
5. select p.id,p.product_name ,pa.unit_price
from products p join product_availability pa
on p.id=pa.prod_id
order by unit_price
desc limit 5;
6.select p.product_name ,pa.unit_price, s.supplier_name
from products p join suppliers s
on p.id=s.id;
join product_availability
pa on pa.prod_id=p.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 pa.unit_price ,o.id,o.order_date ,o.order_reference ,o.customer_id,oi. quantity,pa.unit_price/oi.quantity as total_cost
from product_availability
pa join orders o on pa.prod_id =o.id
join order_items oi on o.id =oi.id
where o.customer_id=1;
9.select c.name ,p.product_name ,o.order_date ,o.order_reference
from customers c join products p on p.id=c.id
join orders o on p.id=o.customer_id
where c.name='Hope Crosby';
10.select o.order_reference ,p.product_name ,pa.unit_price
from orders o join products p on o.id=p.id
join product_availability pa on pa.prod_id=p.id
join order_items oi on oi.order_id=o.id
where o.order_reference='ORD006';
11.select p.product_name ,s.supplier_name,o.order_date,
o.order_reference ,c.name,oi.quantity
from products p join suppliers s on p.id =s.id
join orders o on o.id=s.id
join customers c on c.id=o.customer_id join
order_items oi on o.id=oi.order_id;
12. select distinct s.country ,c.name
from orders o join order_items oi
on oi.order_id=o.id join suppliers s
on oi.supplier_id=s.id
join customers c on c.id=o.customer_id
where s.country='China';
13.


```

When you have finished all of the questions - open a pull request with your answers to the `Databases-Homework` repository.
Expand Down Expand Up @@ -41,10 +92,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.
Empty file.
Loading