Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

PostgreSQL Basic SELECT Statement: Calculate the monthly salary of each employee


19. Write a query to get a monthly salary (rounded up to 2 decimal places) of each employee.
Note : Assume that, the salary field provides the 'annual salary' information.

Sample Solution:

Code:

SELECT first_name, last_name, 
ROUND(salary/12,2) as "Monthly Salary" 
FROM employees;

Sample table: employees


Output:

pg_exercises=# SELECT first_name, last_name,
pg_exercises-# ROUND(salary/12,2) as "Monthly Salary"
pg_exercises-# FROM employees;
 first_name  |  last_name  | Monthly Salary
-------------+-------------+----------------
 Steven      | King        |        2000.00
 Neena       | Kochhar     |        1416.67
 Lex         | De Haan     |        1416.67
 Alexander   | Hunold      |         750.00
 Bruce       | Ernst       |         500.00
 David       | Austin      |         400.00
 Valli       | Pataballa   |         400.00
 Diana       | Lorentz     |         350.00
 ....
 Den         | Raphaely    |         916.67
 Alexander   | Khoo        |         258.33
 Shelli      | Baida       |         241.67
 Sigal       | Tobias      |         233.33
 Guy         | Himuro      |         216.67
 Karen       | Colmenares  |         208.33
 Matthew     | Weiss       |         666.67
 Adam        | Fripp       |         683.33
 ....
 Steven      | Markle      |         183.33
 Laura       | Bissot      |         275.00
 Mozhe       | Atkinson    |         233.33
 James       | Marlow      |         208.33
 ....
 Stephen     | Stiles      |         266.67
 John        | Seo         |         225.00
 Joshua      | Patel       |         208.33
 Trenna      | Rajs        |         291.67
...
 Hermann     | Baer        |         835.83
 Shelley     | Higgins     |        1002.50
 William     | Gietz       |         694.17
(106 rows)

Practice Online



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

Previous: Write a query to select first ten records from a table.
Next: PostgreSQL Restricting and Sorting Data - Exercises, Practice, Solution

What is the difficulty level of this exercise?