Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.
Open
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
22 changes: 20 additions & 2 deletions 2-exercises/task.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,13 +35,31 @@ Open the file `cyf_ecommerce.sql` in VSCode and examine the SQL code. Take a pie
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 DESC;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're using uppercase for clauses try to keep consistent so it's easy to read, for example making it ORDER BY


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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of the wildcard character here :)


4. Retrieve all the products which cost more than 100 showing product id, name, unit price and supplier id.
SELECT p.id, p.product_name ,a.unit_price , a.supp_id FROM products p JOIN product_availability a on p.id= a.prod_id WHERE a.unit_price >100;

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`
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 product_name, unit_price, supplier_name FROM products JOIN product_availability on (products.id = product_availability.prod_id) JOIN suppliers on (suppliers.id = product_availability.supp_id);
s

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).
SELECT product_name,supplier_name FROM products JOIN suppliers on products.id = suppliers.id WHERE 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).

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`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good start Shimen, well done- putting your clauses on new lines can help with legibility :)

Expand Down