Lab 08
Lab 08
Objectives
After completing this lab, you should be able to do the following:
Tools/Software Requirement
MySQL Community Server
MySQL Workbench
Description:
For example, you want to see all the employees whose salary is above average salary. For this
you have to first compute the average salary using AVG function and then compare employees’
salaries with this computed salary. This is possible using subquery. Here the sub query will first
compute the average salary and then main query will execute.
Select *
from emp
where sal >
(select avg(sal)
from emp);
Similarly we want to see the name and empno of that employee whose salary is maximum.
Select *
from emp
where sal = (select max(sal)
from emp);
We want to see how many employees are there whose salary is above average.
Select count(*)
CS220: Database Systems Page 2
from emp
where sal >
(select avg(sal)
from emp);
We want to see those employees who are working in 'DALLAS'. Remember emp and dept are
joined on deptno and loc column is in the dept table. Assuming that wherever the department is
located the employee is working in that city.
Select *
from emp
where deptno IN
(select deptno
from dept
where loc='DALLAS');
Lab Tasks
On the basis of the knowledge of the sub-queries, attempt the following questions using the
Subqueries concept. The information needs can also be met through join operations; however you
need to practice the subqueries. Try to implement subqueries concept as much as possible. You can
use join operation in your queries if required.
Write SQL queries for the following information needs using subquery approach.
b) List accumulative replacement cost of the movies that were never rented.
f) Find those films whose category id is greater than every category id of available films.
Deliverables
CS220: Database Systems Page 3
Save all queries and their results in the word document that you are executing along with the
snapshots of the results. Upload this document to LMS.