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?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework