Lab 9 Tasks Subqueries - Solved
Lab 9 Tasks Subqueries - Solved
Lab 9 Tasks Subqueries - Solved
Query:
Output:
2. Display the employee’s name and salary for all employees who earn more than the
average salary.
Query:
3. Display the employee’s name, job, and hire date for all employees who report to
KING.
Query:
4. List the employee details whose salary is greater than the lowest salary of an
employee belonging to deptno 20.
Query:
Output:
5. Which department has the highest Monthly remuneration bill (Salaries of employees)?
Query:
Output:
6. Display the employees that earn a salary that is higher than the salary of all the clerks.
Sort the result on salary from highest to lowest.
Query:
7. Create a query to display the name, hire date, and salary for all employees who have
both the same salary and commission as employee SCOTT.
Query:
Output:
8. Display the names and salaries of those employees who earn the highest salary in their
department.
Query:
SELECT ename, sal
FROM emp
WHERE sal IN (
SELECT max(sal)
FROM emp
GROUP BY deptno
);
Output:
9. displays employee names, salaries, department numbers, and average salaries for all
the employees who make more than the average salary in their department.
Query:
SELECT
emp.ename,
emp.sal,
emp.deptno,
(SELECT AVG(sal) FROM emp emp2 WHERE emp2.deptno = emp.deptno) AS avg_sal
FROM
emp
WHERE
emp.sal > (SELECT AVG(sal) FROM emp emp2 WHERE emp2.deptno = emp.deptno);
Output:
10. Display all employees whose job and salary is same as employee ‘ALLEN’.
Query:
Output:
DEPARTMENT OF COMPUTER SYSTEMS ENGINEERING
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
Database Management Systems
Lab Experiments
Note: Write a short description and syntax for the statements used. Specify the DBMS
Software/online resource, which you have used to solve the following queries.
Lab 10: To Update and Delete the contents of a Table and use of commit and
rollback commands.
1. Create My_Employee table whose structure and data is same as EMP table. Use
My_Employee table for following queries.
Query:
Update My_Employee
SET ENAME='Drexler'
WHERE empno=7722;
Output:
4. Change the salary to 1000 for all employees with a salary less than 900.
Query:
Update My_Employee
SET sal=1000
WHERE sal<900;
Output:
Query:
Output:
Output:
8. Discard the most recent DELETE statement without discarding the earlier statements.
Query:
ROLLBACK TO SAVEPOINT A;
9. Save the changing permanently.
Query:
Commit;
10. Update the salary of employee 100 to 5000.
Query:
update My_Employee
set sal=5000
WHERE empno=100
11. Update the salary of employee 7722 to a salary same as that of employee “KING”.
Query:
update My_Employee
set sal=(
select sal from My_Employee where ename='KING'
)
where empno=7722;