Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

GTabala/week3 #59

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
35 changes: 33 additions & 2 deletions week-2/mandatory/2-ecommerce-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,41 @@ Below you will find a set of tasks for you to complete to set up a databases of

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

```sql
1. Retrieve all the customers names and addresses who lives in United States
SELECT name, address FROM customers WHERE country='United States';

2. Retrieve all the customers ordered by ascending name
SELECT * FROM customers ORDER BY name;

```
3. Retrieve all the products which cost more than 100
SELECT * FROM products WHERE unit_price > 100;

4. Retrieve all the products whose name contains the word socks
SELECT * FROM products WHERE product_name LIKE '%socks%';

5. Retrieve the 5 most expensive products
SELECT * FROM products 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, p.unit_price, s.supplier_name FROM products p INNER JOIN suppliers s ON s.id = p.supplier_id;

7. Retrieve all the products sold by suppliers based in the . The result should only contain the columns product_name and supplier_name.
SELECT p.product_name, s.supplier_name FROM products p INNER JOIN suppliers s ON s.id = p.supplier_id WHERE s.country = 'United Kingdom';

8. Retrieve all orders from customer ID 1
SELECT * FROM orders WHERE customer_id = 1;

9. Retrieve all orders from customer named Hope Crosby
SELECT o.* FROM orders o INNER JOIN customers c ON c.id = o.customer_id WHERE c.name = 'Hope Crosby';

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, p.unit_price, oi.quantity FROM order_items oi INNER JOIN products p ON p.id = oi.product_id INNER JOIN orders o ON o.id = oi.order_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, p.product_name, s.supplier_name, oi.quantity FROM customers c INNER JOIN orders o ON c.id = o.customer_id INNER JOIN order_items oi ON oi.order_id = o.id INNER JOIN products p ON oi.product_id = p.id INNER JOIN suppliers s ON s.id = p.supplier_id;

12. Retrieve the names of all customers who bought a product from a supplier from China.
SELECT DISTINCT name FROM customers c INNER JOIN orders o ON c.id = o.customer_id INNER JOIN order_items oi ON oi.order_id = o.id INNER JOIN products p ON oi.product_id = p.id INNER JOIN suppliers s ON p.supplier_id = s.id WHERE s.country = 'China';

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

Expand Down
10 changes: 10 additions & 0 deletions week-3/mandatory/2-api/cyf-ecommerce-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Node build artifacts
node_modules
npm-debug.log
# Local development
*.env
*.dev
.DS_Store
# Docker
Dockerfile
docker-compose.yml
Loading