w3resource

PostgreSQL Aggregate Functions and Group By: Get the average salary and number of employees working in a particular designation


5. Write a query to get the average salary and number of employees working in the department which ID is 90.

Sample Solution:

Code:

SELECT AVG(salary),count(*) 
FROM employees 
WHERE department_id = 90;

Sample table: employees


Output:

pg_exercises=# SELECT AVG(salary),count(*)
pg_exercises-# FROM employees
pg_exercises-# WHERE department_id = 90;
        avg         | count
--------------------+-------
 19363.333333333333 |     3
(1 row)

Practice Online


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming