SQL stands for Structured Query Language, which used in the database to retrieve data, update and modify data in relational databases like MySql, Oracle, etc. And a query is a question or request for data from the database, that is if we ask someone any question then the question is the query. Similarly, when we want any data from the database then we write the query in SQL to get that data. In this article, we are talking about how we can find the monthly salary of employees if annual salary is given.
To create a database there is a query we need to use in the SQL platform, like MySql, Oracle, etc. The query is,
CREATE DATABASE database_name;
CREATE DATABASE GeeksforGeeks_salary;
Using the database
To use the database there is a query we need to use in the SQL platform, like MySql, Oracle, etc. The query is,
Add tables in the database
To create tables in a database there is a query we need to use in the SQL platform, like MySql, Oracle, etc. The query is,
CREATE TABLE table_name(
CREATE TABLE GFG_salary(
To see the table use the below:
If we use the Microsoft SQL server then we need to use EXEC sp_help in place of DESC. In the Microsoft SQL server, the DESC command is not an SQL command, it is used in Oracle.
Add value into the table
To add value to the table there is a query we need to use in the SQL platform, like MySql, Oracle, etc. The command is,
INSERT INTO table_name(
For example, here the query will be,
INSERT INTO `GFG_salary` (`emp_ID`, `emp_name`, `emp_course_mentor`, `emp_An_salary`)
(1, 'EmpABC', 'C++', '480000'),
(2, 'EmpDEF', 'JAVA', '540000'),
(3, 'EmpXYZ', 'DSA', '600000'),
(4, 'EmpIJK', 'Python', '650000');
Data present in the table after insertion
SELECT * FROM GFG_salary;
Now we have to find the monthly salary of employees from the table where the annual salary is given,
To find this, we have to divide the annual salary by 12 and make an alias column as Monthly Salary to view the monthly salary o each employee. And to view other details present in the table select those columns in the select statement.
SELECT emp_name, (emp_An_salary/12) AS 'Monthly Salary' ,
emp_An_Salary AS 'Annual Salary' FROM GFG_salary ;
Now round of the salary by 2 decimal point, to do that we have used round function, see below
SELECT emp_name, round(emp_An_salary/12,2) AS 'Monthly Salary' ,
emp_An_Salary AS 'Annual Salary' FROM GFG_salary
To find the monthly salary of particular employees, then use the where clause with a condition, see below,
SELECT emp_name, round(emp_An_salary/12,2) AS 'Monthly Salary' , emp_An_Salary AS 'Annual Salary'
emp_ID = 1
emp_name = 'EmpABC' ;
Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation
Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our Complete Interview Preparation