Browse Source

modified some answers

master
Ernest Debruyne 2 years ago
parent
commit
1b4930fc25

+ 2
- 2
How-to-code-subqueries.sql View File

@@ -1,8 +1,8 @@
-- Exercise 1

SELECT DISTINCT category_name
SELECT category_name
FROM categories
WHERE category_id IN (SELECT category_id
WHERE category_id IN (SELECT DISTINCT category_id
FROM products)
ORDER BY category_name;


+ 2
- 2
How-to-code-summary-queries.sql View File

@@ -7,8 +7,8 @@ FROM orders;
-- Exercise 2

SELECT category_name,
COUNT(products),
MAX(list_price)
COUNT(product_id) AS count,
MAX(list_price) AS max_price
FROM categories c JOIN products p
ON c.category_id = p.category_id
GROUP BY category_name

+ 1
- 0
How-to-create-databases.sql View File

@@ -1,5 +1,6 @@
-- exercise 1

SELECT * FROM addresses;

-- exercise 2


+ 1
- 1
How-to-retrieve-data-from-a-single-table.sql View File

@@ -29,7 +29,7 @@ SELECT product_name,
list_price,
discount_percent,
ROUND((discount_percent/100) * list_price, 2) AS discount_amount,
ROUND(list_price - ((discount_percent/100) * list_price), 2) AS discount_price
ROUND(list_price - (discount_percent/100) * list_price, 2) AS discount_price
FROM products
ORDER BY discount_price DESC
LIMIT 5;

+ 3
- 3
How-to-retrieve-data-from-two-or-more-tables.sql View File

@@ -3,7 +3,8 @@
SELECT category_name,
product_name,
list_price
FROM categories g JOIN products p
FROM categories c JOIN products p
ON c.category_id = p.category_id
ORDER BY category_name, product_name ASC;

-- Exercise 2
@@ -52,8 +53,7 @@ ORDER BY last_name, order_date, product_name;
SELECT p.product_name,
p.list_price
FROM products p JOIN products p2
ON p.list_price = p2.list_price
WHERE p.product_id != p2.product_id
ON p.list_price = p2.list_price AND p.product_id <> p2.product_id
ORDER BY product_name;

-- Exercise 6

Loading…
Cancel
Save