Setting Up an Environment

In this, we will create a database with a required table. We will cover all the basic steps to create a table in a database.

STEP 1: Let’s create a database.

CREATE DATABASE geeks

STEP 2: After executing this query, we can see our database has been created. Now let’s use our database

USE geeks

STEP 3: As we are done with creating the database, now let’s create a table in that database.

Create Table:

CREATE TABLE w3wiki(
id INT PRIMARY KEY,
name VARCHAR(10),
department VARCHAR(10),
salary INT
);

STEP 4: Now, we are done with creating a table with specified columns. Lets insert some values in our table and display them.

Insert Values in Table:

--inserting values in the table 'w3wiki'
INSERT INTO w3wiki (id, name, department, salary)
VALUES
(101, 'Vishu', 'IT', 50000),
(102, 'Sumit', 'HR', 40000),
(103, 'Neeraj', 'HR', 25000),
(104, 'Aayush', 'IT', 35000),
(105, 'Harsh', 'IT', 32000),
(106, 'Rahul', 'HR', 30000),
(107, 'Vivek', 'IT',55000 );

-- displaying the table's data
SELECT * FROM w3wiki;

Output:

Table – w3wiki

We can see our table is now ready to use.

SQL Query to find Employees With Higher Salary than Their Department Average ?

Analyzing and understanding salary distributions within departments is a critical aspect of human resource management. In this article, we will explore SQL queries to calculate the average salary for each department and identify employees whose salaries exceed their departmental averages.

These queries provide valuable insights for performance evaluations and salary adjustment strategies. We will demonstrate two methods: one without using the JOIN() method and another using JOIN() for a comprehensive understanding. Let’s understand the practical examples to enhance your SQL skills and analytical capabilities in database management.

Similar Reads

Setting Up an Environment

In this, we will create a database with a required table. We will cover all the basic steps to create a table in a database....

Finding Departmental Average

Lets calculate the average salary from each department....

Finding all the Employees Whose Salaries are Higher Than those of their Respective Departments

Method 1: Without using JOIN()...

Conclusion

Overall, finding average salaries from each department as well as employees details those are receiving higher salaries than departmental average can help in many ways like performance of employees. This can also help in developing salaries adjustment strategies. We have covered two very easy and basic ways through which we can easily achieved the mentioned tasks. We have covered ways in which we have included JOIN() as well as without JOIN(). We have also covered how we can find the departmental average from the table. Now, have a good understanding of developing queries related to the topic and also some similar related queries....

Contact Us