Learn Aggregate Functions and Calculations

 Aggregate Functions

  • Count( )
  • Sum( )
  • Max( )
  • Min( ) 
  • Min( )
  • Avg( )

we will use the following employees table for our example

 

Aggregate Function

COUNT( )

Write SQL query to retrieve the total number of employees.

 

SELECT COUNT(*) AS count_employees FROM employees;

 

count

 

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

count

 

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;

 

sum


 MAX( )

Write a query to retrieve the max salary from employees table.

 

SELECT MAX(salary) as max_of_salary FROM EMPLOYEES;

max

 

 MIN( )

Write a query to retrieve the minimum salary from employees table.

 

SELECT MIN(salary) as min_of_salary FROM employees;

 

min

AVG( )

Write a query to retrieve the average salary from employees table.

 

SELECT AVG(salary) as avg_of_salary FROM employees;

avg








Post a Comment

0 Comments