Essential Question: How can I use functions in SQL to get the count, average, and sum of a field?
Mastery Objectives:
SWBAT use formulas to calculate queries in SQL.
SWBAT use formulas to count records in SQL.
Directions: SQL has formulas that can be used to calculate and count records. The field you choose needs to be numerical. These are the formats for each of the formulas:Â
Formula to count the records:
SELECT COUNT(column_name)
FROM table_name;
Formula to calculate the average:
SELECT AVG(column_name)
FROM table_name;
Formula to calculate the sum:
SELECT SUM(column_name)
FROM table_name;
Your assignment is to run the queries below in the SQL editor https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_count, take a screen shot and paste it into a google doc, then write a little description of the results. Submit your google doc to google classroom.
SELECT COUNT(ProductID) FROM Products;
SELECT AVG(ProductID) FROM Products;
SELECT SUM(ProductID) FROM Products;
SELECT COUNT(CategoryID) FROM Products;
SELECT AVG(CategoryID) FROM Products;
SELECT SUM(CategoryID) FROM Products;
Create a query that counts Price
Create a query that finds the average of Price
Create a query that finds the sum of Price
Create a query that counts CustomerID from customers
Create a query that finds the average of customerID from customers