Skip to content

A collection of SQL practice questions designed to improve skills in querying, managing, and manipulating relational databases. These exercises cover various SQL topics, including SELECT statements, joins, subqueries, aggregation, and data manipulation.

Notifications You must be signed in to change notification settings

piyush-ghavari/SQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

SQL

What is SQL?

SQL (Structured Query Language) is a domain-specific programming language used for managing and manipulating relational databases. It is the standard language for interacting with databases to perform tasks such as retrieving, inserting, updating, and deleting data. SQL allows users to create and manage database structures, define relationships between tables, and query data using a series of commands.

Key Components:

  • Tables: Data is organized in rows and columns.
  • Columns: Define the structure of the table (e.g., id, name, salary).
  • Rows: Represent individual records in a table.
  • Primary Key: A unique identifier for each record.
  • Foreign Key: Establishes relationships between table

With questions i perform my queries and solves the problem statements:

-------------------------------------------------------------------

First : I Create a database

Screenshot 2025-01-12 190003

Screenshot 2025-01-12 185853

--------------------------------------------------------------------

Second: I create three tables

WhatsApp Image 2025-01-12 at 18 55 03_ebbed52f

Screenshot 2025-01-12 185906

Screenshot 2025-01-12 192949

----------------------------------------------------------------------

Third : I insert a data into the Department table

Screenshot 2025-01-12 193117

Output

Screenshot 2025-01-12 193216

------------------------------------------------------------------------

Fourth: I insert a data into the Employee table

Screenshot 2025-01-12 193743

Output

Screenshot 2025-01-12 193245

-----------------------------------------------------------------------

Fifth : I insert a data into project_assigment table

Screenshot 2025-01-12 193807

Ouput

Screenshot 2025-01-12 193311

----------------------------------------------------------------------

sixth : I practice questions taking these tables and solve them:

-----------------------------------------------------------------------

Question 1. Find the Second Highest Salary

Problem: Find the second highest salary from the Employee table.

question 1

-----------------------------------------------------------------------

2. List Departments with More Than 3 Employees

Problem: List department names where the number of employees is greater than 3.

question 2

-----------------------------------------------------------------------

3.. Retrieve the Top 3 Highest-Paid Employees in Each Department

Problem: List the top 3 highest-paid employees from each department.

question 3

-----------------------------------------------------------------------

4. Fetch the second-highest salary from the employees table.

question 4

-------------------------------------------------------------------------

5.Retrieve names of employees whose names start with "J" and end with "N".

question 5

---------------------------------------------------------------------------

6. Display the total count of employees grouped by their department.

question 6

-----------------------------------------------------------------------

7.Find employees who have never been assigned a project id .

question 7

-------------------------------------------------------------------------

8. Find the maximum, minimum, and average salary of employees in each department.

question 8

--------------------------------------------------------------------------

9. Fetch names of employees who earn more than the average salary in their department.

question 9

-------------------------------------------------------------------------

10. Find names of employees who work in the same department as "John Doe".

question 10

-------------------------------------------------------------------------

11. Find departments with more than 5 employees.

question 11

-------------------------------------------------------------------------

12.Fetch employees with salaries in the top 10%.

12

--------------------------------------------------------------------------

13.Retrieve the list of duplicate records in a table.

Screenshot 2025-01-12 145404

---------------------------------------------------------------------------

14. Write a query to find employees with the same salary.

13

---------------------------------------------------------------------------

15. Calculate the running total of salaries.

Screenshot 2025-01-12 200141

------------------------------------------------------------------------

16. Find the rank of employees based on their salary within each department.

Screenshot 2025-01-12 160453

-----------------------------------------------------------------------

17.Fetch the department with the highest average salary.

16

-----------------------------------------------------------------------

18. Find employees whose salary is greater than the department average.

17

-----------------------------------------------------------------------

19. Rank employees by salary within each department.

18 1

-------------------------------------------------------------------------

20.Find the percentage contribution of each employee's salary within their department.

18

About

A collection of SQL practice questions designed to improve skills in querying, managing, and manipulating relational databases. These exercises cover various SQL topics, including SELECT statements, joins, subqueries, aggregation, and data manipulation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published