Week 3 - SQL Continued (1) (2) (2)
Week 3 - SQL Continued (1) (2) (2)
01 Summarize data
02 Group Data
03 Join 2 unique tables
04 SQL Having
01
Summarize Data
SELECT Explanation
• SELECT: Specifies the columns to retrieve.
• COUNT(*): Counts the number of sales for each
COUNT(*) AS total_sales, product.
SUM(amount) AS total_amount, • SUM(amount): Sums up the total sales amount for
AVG(amount) AS average_amount, each product.
MAX(amount) AS max_sale, • AVG(amount): Calculates the average sale amount
MIN(amount) AS min_sale for each product.
• MAX(amount): Finds the maximum sale amount for
FROM
each product.
sales • MIN(amount): Finds the minimum sale amount for
each product.
• FROM: Specifies the table from which to select the
data.
02
Group Data
SELECT column_name(s) SELECT COUNT(ProductID), SupplierID
FROM table_name FROM Products
WHERE condition Where Price > 15
GROUP BY column_name(s) GROUP BY SupplierID
ORDER BY column_name(s); ORDER BY COUNT(ProductID) DESC;
03
Join 2
Unique Tables
Joins Explained
Inner Join
SELECT columns
FROM table1
INNER JOIN table2
ON table1.common_column = table2.common_column;
Replace INNER JOIN by LEFT JOIN, RIGHT JOIN, OUTER JOIN for other joins
Joins Explained
SQL Having
Having Example
SELECT COUNT(CustomerID),
Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DES
C;
THAT’S A
WRAP
ACTION PLAN
● Complete assigned reading as
required
● Watch the assigned video as
required
● Complete all assigned activities
and submit via blackboard by
due date
</>
Reading Homework
Chapters 9 – 12 Assignment 1 - SQL
Sam’s Teach Yourself
SQL in 10 Minutes
QUESTIONS?
THE END
BREAK