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:
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.
Contact Us