0% found this document useful (0 votes)
10 views6 pages

DBA Alhasan Mohammed

The document contains SQL queries submitted by Alhasan Mohammed for the academic year 2025/2026, focusing on various employee and department-related data retrieval tasks. Each query is accompanied by an explanation of its purpose, such as finding employees earning above average salaries, identifying the highest paid employee, and checking department statistics. The document serves as a practical guide for executing specific database queries to analyze employee salary and departmental information.

Uploaded by

starfortwars
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

DBA Alhasan Mohammed

The document contains SQL queries submitted by Alhasan Mohammed for the academic year 2025/2026, focusing on various employee and department-related data retrieval tasks. Each query is accompanied by an explanation of its purpose, such as finding employees earning above average salaries, identifying the highest paid employee, and checking department statistics. The document serves as a practical guide for executing specific database queries to analyze employee salary and departmental information.

Uploaded by

starfortwars
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Database queries

Submitted by:
Alhasan Mohammed

Academic year: Date of submission:


2025/2026 21/2/2025
1- Find Employees Earning More than the Average Salary:

select ename,sal from emp where sal>(select avg(sal) from emp )

Result:

Explanation: i compared the salary of employees that are more than the average of
salaries in the table

2- Find the Highest Paid Employee(s):

select ename,sal from emp where sal=(select max(sal) from emp )

Result:

Explanation: checked the employees whose salaries are equal to the highest salary
3- Find Employees Working in the Same Department as 'Azad’

select ename,deptname from emp where deptname=(select deptname from emp


where ename="Azad")

Result:

Explanation: checked the employees who are under the same department name as azad

4- Find Employees Who Have the Same Job Title as 'Newroz’:

select ename,job from emp where job=(select job from emp where
ename="Newroz")

Result:

Explanation: checked all those who have the same job name as newroz
5- Find Departments That Have More Than One Employee:

SELECT deptname, COUNT(ename) FROM emp GROUP BY deptname HAVING


COUNT(ename) > 1;

Result:

Explanation: checked the department names that have more than 1 employees by
comparing to the numbers of employees in each department (using group by)
6- Find Employees in the Department with the Lowest Average Salary:

SELECT sal,ename,deptname FROM emp WHERE deptname = ( SELECT deptname


FROM emp GROUP BY deptname ORDER BY AVG(sal) limit 1);

Result:

Explanation: checked the lowest average salary in each department by grouping the
department names and then order them based on the average of the salaries of
employees, (note: since grouping by department will result in multiple rows output,
I limit it by one to specify the lowest average salary since its ascending)

7- Find Employees Who Earn More Than the Highest Paid Employee in 'BA' Department:

SELECT sal,ename,deptname FROM emp WHERE sal > ( SELECT max(sal) FROM emp
where deptname="BA");

Results:
Explanation: I compared salary of employees with the highest salary form BA department

8- Find Departments Where No Employee Earns More Than 5000:

SELECT deptname FROM emp WHERE sal <= 5000 group by deptname

Result:

Explanation: i compared the salaries of every employee of every department that are less
or equal to 5000 and to avoid redundancy i grouped them by deptname

You might also like