18.3 Aggregate functions: AVG(), SUM(), GROUP BY
Sometimes you may need to execute functions on the data before extracting it. See how this may be done below:
-
Write a SQL statement that shows the average salary of the employees in each location. Display LocationID, Location City, AverageSalary.
- functions
- AVG()
- GROUP BY
-
Write a SQL statement that shows how many employees work in the New York City and Denver locations. Display Location City and Total Employees.
- COUNT()
-
Write a SQL statement that shows the total salary of the employees for each location. Display Location City and Total.
- SUM()
-
Create a Summary Query to Display the average and minimum salary of all job positions. Display job position, average salary, and minimum salary.
- MIN()
-
Calculate the difference between the current salary and the maximum salary of each Regional Manager. Name the calculated field “SalaryDifference.” Show last name, salary, maximum salary, and SalaryDifference.
- Calculated fields (not the same as functions)