@@ -1,19 +1,40 @@ | |||
-- Exercise 1 | |||
SELECT DISTINCT category_name | |||
FROM categories c JOIN products p | |||
ON c.category_id = p.category_id | |||
WHERE ( | |||
SELECT DISTINCT category_name | |||
FROM categories c JOIN products p | |||
ON c.category_id = p.category_id) | |||
ORDER BY category_name | |||
-- Exercise 2 | |||
SELECT product_name,list_price | |||
FROM products | |||
WHERE ( | |||
SELECT product_name,list_price | |||
FROM products) | |||
ORDER BY list_price DESC; | |||
-- Exercise 3 | |||
SELECT category_name | |||
FROM categories | |||
WHERE ( | |||
SELECT product_id | |||
FROM products) | |||
WHERE product_id NOT EXISTS | |||
ORDER BY category_id DESC; | |||
-- Exercise 4 | |||
SELECT email_address, order_id,sum(item_price) AS order_total | |||
FROM administrators a JOIN orders o | |||
ON a.admin_id = o.admin_id | |||
ORDER BY email_address ASC; | |||
-- Exercise 4 part 2 | |||
__ | |||
-- Exercise 5 | |||
SELECT product_name, discount_percent | |||
FROM products | |||
ORDER BY discount_percent DESC; | |||
-- Exercise 6 | |||
SELECT email_address, order_id, order_date | |||
FROM administrators a JOIN orders o | |||
on a.admin_id = o.order_id; |
@@ -1,19 +1,38 @@ | |||
-- Exercise 1 | |||
SELECT COUNT(order_id) AS order_count, SUM(tax_amount) AS tax_total | |||
FROM orders; | |||
-- Exercise 2 | |||
SELECT category_name, COUNT(product_name) AS product_count, sum(list_price) | |||
FROM categories c JOIN products p | |||
ON c.category_id = p.category_id. | |||
ORDER BY category_name ASC; | |||
-- Exercise 3 | |||
SELECT email_adress,SUM(item_price*quantity) AS item_price_total, SUM(discount_amount*quantity) AS discount_amount | |||
FROM administrators c JOIN order_items l | |||
ON c.admin_id = l.admin_id | |||
ORDER BY item_price DESC; | |||
-- Exercise 4 | |||
SELECT email_adress, COUNT(order_id) AS order_count, SUM((ship_amount-tax_amount)*quantity) AS order_total | |||
FROM administrators c JOIN orders o | |||
ON c.admin_id_id = o.admin_id | |||
WHERE admin_id > 1 | |||
ORDER BY SUM(list_price) DESC; | |||
-- Exercise 5 | |||
SELECT email_adress, COUNT(order_id) AS order_count, SUM((ship_amount-tax_amount)*quantity) AS order_total | |||
FROM administrators c JOIN orders o | |||
ON c.admin_id_id = o.admin_id | |||
WHERE order_id >= 400 | |||
ORDER BY SUM(list_price) DESC; | |||
-- Exercise 6 | |||
-- Exercise 7 | |||
SELECT email_adress, sum(product_id) AS number_of_products | |||
FROM administrators a JOIN products p | |||
ON a.admin_id = p.admin_id | |||
ORDER BY admin_id ASC; |
@@ -1,22 +1,41 @@ | |||
-- Exercise 1 | |||
SELECT product_code,product_name,list_price,discount_percent | |||
FROM products | |||
ORDER BY list_price DESC; | |||
-- Exercise 2 | |||
SELECT CONCAT(last_name+', '+first_name) AS full_name | |||
FROM customers; | |||
-- Exercise 3 | |||
SELECT product_name,list_price,date_added | |||
FROM products | |||
WHERE list_price > 500 AND list_price < 1200 | |||
ORDER BY date_added DESC; | |||
-- Exercise 4 | |||
SELECT product_name,list_price,discount_percent,(list_price*discount_percent/100)AS discount_amount,(list_price -(list_price*discount_percent/100))AS discount_price | |||
FROM products | |||
ORDER BY list_price DESC LIMIT 5; | |||
-- Exercise 5 | |||
SELECT item_id,item_price,discount_amount,quantity,(item_price*quantity)AS price_total,(discount_amount*quantity)AS discount_total,(item_price*quantity)-(discount_amount*quantity)AS item_total | |||
FROM order_items | |||
ORDER BY item_price DESC LIMIT 5; | |||
-- Exercise 6 | |||
SELECT order_id,order_date,ship_date | |||
FROM orders | |||
WHERE ship_date IS null; | |||
-- Exercise 7 | |||
SELECT NOW()=today_unformatted, | |||
(DD-Mon-YYYY)=today_formatted; | |||
-- Exercise 8 | |||
SELECT list_price as price, | |||
discount_percent as tax_rate, | |||
(list_price*discount_percent/100) AS tax_amount, | |||
list_price*(list_price*discount_percent/100) AS total | |||
FROM products; |
@@ -1,19 +1,43 @@ | |||
-- Exercise 1 | |||
SELECT category_name, product_name, list_price | |||
FROM categories c JOIN products p | |||
ON c.category_id = p.category_id | |||
ORDER BY category_name,product_name ASC; | |||
-- Exercise 2 | |||
SELECT first_name, last_name, line1, city, state, zip_code | |||
FROM customers c JOIN addresses a | |||
ON c.customer_id = a.customer_id | |||
WHERE state='NJ' | |||
ORDER BY customers ASC; | |||
-- Exercise 3 | |||
SELECT first_name, last_name, line1, city, state, zip_code | |||
FROM customers c JOIN addresses a | |||
ON c.customer_id = a.customer_id | |||
ORDER BY first_name ASC; | |||
-- Exercise 4 | |||
SELECT last_name, first_name, order_date, product_name, item_price, discount_amount, quantity | |||
FROM customers c JOIN products p AND orders o JOIN order_items i | |||
ON c.customer_id = p.category_id AND o.order_id = i.order_id | |||
ORDER BY last_name, order_date, product_name ASC; | |||
-- Exercise 5 | |||
SELECT product_name, list_price | |||
FROM products( | |||
SELECT product_name, list_price | |||
FROM products) | |||
ORDER BY product_name ASC; | |||
-- Exercise 6 | |||
SELECT product_name, list_price | |||
FROM products( | |||
SELECT product_name, list_price | |||
FROM products) | |||
WHERE product_name IS null | |||
ORDER BY product_name ASC; | |||
-- Exercise 7 | |||
SELECT ship_date, order_id, order_date | |||
FROM orders; |