![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Divide a column to get monthly salary of employees in a MySQL Query?
Let us first create a table −
mysql> create table DemoTable1957 ( EmployeeId int, EmployeeName varchar(20), EmployeeSalary int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1957 values(1,'Chris',240000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(2,'Bob',120000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(3,'David',180000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1957 values(4,'Mike',650000); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1957;
This will produce the following output −
+------------+--------------+----------------+ | EmployeeId | EmployeeName | EmployeeSalary | +------------+--------------+----------------+ | 1 | Chris | 240000 | | 2 | Bob | 120000 | | 3 | David | 180000 | | 4 | Mike | 650000 | +------------+--------------+----------------+ 4 rows in set (0.00 sec)
Here is the query to get monthly salary of employee:
mysql> select EmployeeName,EmployeeSalary/12 As MonthlySalary from DemoTable1957;
This will produce the following output −
+--------------+---------------+ | EmployeeName | MonthlySalary | +--------------+---------------+ | Chris | 20000.0000 | | Bob | 10000.0000 | | David | 15000.0000 | | Mike | 54166.6667 | +--------------+---------------+ 4 rows in set (0.00 sec)
Advertisements