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
15 changes: 12 additions & 3 deletions week-1/mandatory/2-classes-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ Below you will find a set of tasks for you to complete to consolidate and extend
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 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.00);
5-insert into rooms( room_no, room_type, rate) values (501,'PENTHOUSE', 185.00), (502,'PENTHOUSE', 185.00);
6-insert into rooms( room_no, room_type, rate) values (503,'PREMIER PLUS', 143.00);
7- select count(room_no)
from reservations where checkin_date between '2020-08-01'and '2020-08-31'
8- select sum(checkout_date - checkin_date) from reservations where room_no between 201 and 299;
9- select count(*), sum(total), avg(total) from invoices where total >300;
10- select sum(checkout_date - checkin_date) from reservations group by room_no/100 ;
```

When you have finished all of the questions - open a pull request with your answers to the `Databases-Homework` repository.

Expand Down
46 changes: 45 additions & 1 deletion week-2/mandatory/2-ecommerce-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,62 @@ Open the file `cyf_ecommerce.sql` in VSCode and examine the SQL code. Take a pie
## Task

Once you understand the database that you are going to work with, solve the following challenge by writing SQL queries using everything you learned about SQL:

1. Retrieve all the customers' names and addresses who live in the United States
select name, address from customers where country ='United States';

2. Retrieve all the customers in ascending name sequence
select * from customers order by name ;

3. Retrieve all the products whose name contains the word `socks`
select * from products where product_name like '%socks%';

4. Retrieve all the products which cost more than 100 showing product id, name, unit price and supplier id.
select a.prod_id, p.product_name, a.unit_price, a.supp_id from products p join product_availability a on (a.prod_id = p.id) where a.unit_price >100 ;

5. Retrieve the 5 most expensive products
select * from product_availability order by unit_price DESC limit 5;

6. Retrieve all the products with their corresponding suppliers. The result should only contain the columns `product_name`, `unit_price` and `supplier_name`
select p.product_name, a.unit_price, s.supplier_name from products p join product_availability a on (a.prod_id = p.id) join suppliers s on (a.supp_id = s.id) ;

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`.
select p.product_name, s.supplier_name from products p join product_availability a on(a.prod_id = p.id) join suppliers s on (a.supp_id = s.id) where s.country = 'United Kingdom';

8. Retrieve all orders, including order items, from customer ID `1`. Include order id, reference, date and total cost (calculated as quantity * unit price).

select o.order_reference, o.order_date from orders o join order_items i on (i.order_id = o.id) join product_availability a on (a.prod_id = i.product_id) where o.customer_id = 1;
////////////I don't understand what they exactly want from this question ////////////////

9. Retrieve all orders, including order items, from customer named `Hope Crosby`
select o.* from orders o join customers c on (o. customer_id = c.id) where c.name = 'Hope Crosby';
////// what do yo mean by including order items ////////////////////////////

10. Retrieve all the products in the order `ORD006`. The result should only contain the columns `product_name`, `unit_price` and `quantity`.
select p.product_name , a.unit_price, i.quantity from orders o join order_items i on(i.order_id = o.id) join product_availability a on (i.supplier_id = a.supp_id) join products p on (p.id = a. prod_id)
where o.order_reference = 'ORD006';

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`.
select c.name, o.order_reference, o.order_date, s.supplier_name , i.quantity
from customers c join
orders o on(c.id= o.customer_id) join
order_items i on (o.id = i. order_id) join
products p on (i.product_id = p.id) join
suppliers s on (s.id =i.supplier_id);

12. Retrieve the names of all customers who bought a product from a supplier based in China.
select c.name from customers c join orders o on(c.id= o.customer_id) join
order_items i on (o.id = i. order_id) join
suppliers s on (s.id =i.supplier_id)
where s.country = 'China';


13. List all orders giving customer name, order reference, order date and order total amount (quantity * unit price) in descending order of total.
select c.name, o.order_reference, o.order_date, sum (quantity * unit_price) as total
from customers c join orders o on(c.id= o.customer_id) join
order_items i on (o.id = i. order_id) join
product_availability a on (i.supplier_id = a.supp_id)
group by c.name, o.order_reference, o.order_date
ORDER BY totaL DESC ;



1 change: 1 addition & 0 deletions week-3/cyf-hotels-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading