w3resource

PostgreSQL Aggregate Functions and Group By: Find the maximum salary paid to the employee working as a Programmer


4. Write a query to get the maximum salary of an employee working as a Programmer.

Sample Solution:

Code:

-- Retrieve the maximum salary among employees with the job ID 'IT_PROG'
SELECT MAX(salary) 
FROM employees 
WHERE job_id = 'IT_PROG';

Explanation:

  • This SQL query is designed to retrieve the maximum (highest) salary among employees who have the job ID 'IT_PROG'.
  • The MAX() function is an aggregate function in SQL that calculates the maximum value in a column.
  • salary is presumably a column in the employees table that holds the salary information for each employee.
  • job_id is likely a column in the employees table that identifies the job position of each employee.
  • The WHERE clause filters the rows to include only those where the job_id is equal to 'IT_PROG'.
  • The query calculates the maximum value in the salary column for all rows in the employees table that meet the specified condition.

Sample table: employees


Output:

pg_exercises=# SELECT MAX(salary)
pg_exercises-# FROM employees
pg_exercises-# WHERE job_id = 'IT_PROG';
   max
---------
 9000.00
(1 row)

Relational Algebra Expression:

Relational Algebra Expression: Find the maximum salary paid to the  employee working as a Programmer.

Relational Algebra Tree:

Relational Algebra Tree: Find the maximum salary paid to the  employee working as a Programmer.

Practice Online


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

Previous: Write a query to get the minimum salary from employees table.
Next: Write a query to get the average salary and number of employees working in the department which ID is 90.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/postgresql-exercises/aggregate-function-and-groupby/aggregate-function-and-groupby-exercise-4.php