Aggregate Functions
- Count( )
- Sum( )
- Max( )
- Min( )
- Min( )
- Avg( )
we will use the following employees table for our example
COUNT( )
Write SQL query to retrieve the total number of employees.
SELECT COUNT(*) AS count_employees FROM employees;
Write SQL query to retrieve the number of employees in department number 3.
SELECT COUNT(*) AS no_of_emp FROM employees WHERE dept_id=3
Note: count(*) will retrieve all values including NULL values from the specified column
SUM( )
Write a query to retrieve the sum of salary column
select sum(salary) as sum_of_salary from employees;
MAX( )
Write a query to retrieve the max salary from employees table.
SELECT MAX(salary) as max_of_salary FROM EMPLOYEES;
MIN( )
Write a query to retrieve the minimum salary from employees table.
SELECT MIN(salary) as min_of_salary FROM employees;
AVG( )
Write a query to retrieve the average salary from employees table.
SELECT AVG(salary) as avg_of_salary FROM employees;
0 Comments