Anil Patel Architect - Data
Engineering & Analytics
@anilpatel Career Transition Coach
Top 30
SQL Interview Questions
Part - 3
Anil Patel Architect - Data
Engineering & Analytics
@anilpatel Career Transition Coach
Introduction
SQL (Structured Query Language) is a programming language used for managing and
manipulating relational databases. It allows users to interact with databases by performing
tasks like querying data, inserting records, updating information, and deleting entries,
making it essential for handling data effectively in various applications.
Table : Employees
ID Name Department Salary
1. Brayden IT 52000
2. Chris HR 54000
3. Ailani Marketing 65000
4. Dalton Finance 68000
5. Lara IT 46000
6. Anala Finance 71000
7. Marshall HR 42000
8. Ishana Marketing 59000
Anil Patel Architect - Data
Engineering & Analytics
@anilpatel Career Transition Coach
Q21. Retrieve names and salaries of employees with a
salary higher than the average salary of all employees
SELECT Name, Salary
FROM Employees
WHERE Salary > ( SELECT AVG( Salary ) FROM Employees ) ;
Q22. Retrieve employees with the highest salary from
the Employees Table
SELECT *
FROM Employees
WHERE Salary = ( SELECT MAX( Salary ) FROM Employees ) ;
Q23. Update salaries of all employees in the Finance
Department by adding 7000
UPDATE Employees
SET = Salary + 7000
WHERE Department = ' Finance ' ;
Anil Patel Architect - Data
Engineering & Analytics
@anilpatel Career Transition Coach
Q24. Insert a new employee record into the Employees
Table
INSERT INTO Employees ( Name, Department, Salary )
VALUES ( ' Justin ', ' IT ', 44000 ) ;
Q25. Calculate the average salary in each department
SELECT Department, AVG( Salary )
FROM Employees
GROUP BY Department ;
Q26. Count the number of employees in each
department
SELECT Department, COUNT(*)
AS NumEmployees
FROM Employees
GROUP BY Department ;
Anil Patel Architect - Data
Engineering & Analytics
@anilpatel Career Transition Coach
Q27. Retrieve names and salaries of employees with a
salary equal to at least one HR Department employee
SELECT Name, Salary
FROM Employees
WHERE Salary = ANY ( SELECT Salary FROM Employees WHERE
Department = ' HR ' ) ;
Q28. Retrieve names and salaries of employees within a
range of +/- 2000 from the average salary of all
employees
SELECT Name, Salary
FROM Employees
WHERE Salary BETWEEN ( SELECT AVG( Salary ) FROM
Employees ) - 2000 AND ( SELECT AVG( Salary ) FROM
Employees ) + 2000 ;
Anil Patel Architect - Data
Engineering & Analytics
@anilpatel Career Transition Coach
Q29. Retrieve names and salaries of employees with a
salary higher than all Finance Department employees
SELECT Name, Salary
FROM Employees
WHERE Salary > ALL ( SELECT Salary FROM Employees WHERE
Department = ' Finance ') ;
Q30. Retrieve departments with more than 3
employees and display the department name along
with the count of employees
SELECT Department, COUNT(*)
AS NumEmployees
FROM Employees
GROUP BY Department
HAVING COUNT(*) > 3 ;
Follow for more amazing content like this !