From f874399b0a9501087df49ad086ed28c33b4b5623 Mon Sep 17 00:00:00 2001 From: ShimenAfshar Date: Tue, 14 Feb 2023 20:05:54 +0000 Subject: [PATCH] up to task 8 --- 2-exercises/task.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/2-exercises/task.md b/2-exercises/task.md index c48d2286..4d2b26b2 100644 --- a/2-exercises/task.md +++ b/2-exercises/task.md @@ -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; + 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 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`.