0% found this document useful (0 votes)
28 views4 pages

Query Sol Sessional 1

The document discusses relational algebra and SQL queries for a university database schema. It provides examples of queries to find employee names and addresses, employee names working on all projects for a department, project numbers involving employees with a last name, and maximum employee salary. It also provides SQL queries to find faculty teaching in all rooms, faculty with enrollment over 5, average student age by level, and faculty teaching only in a specific room with class count.

Uploaded by

Vikas Jat
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)
28 views4 pages

Query Sol Sessional 1

The document discusses relational algebra and SQL queries for a university database schema. It provides examples of queries to find employee names and addresses, employee names working on all projects for a department, project numbers involving employees with a last name, and maximum employee salary. It also provides SQL queries to find faculty teaching in all rooms, faculty with enrollment over 5, average student age by level, and faculty teaching only in a specific room with class count.

Uploaded by

Vikas Jat
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/ 4

Que 2.a) Consider the following Schema for the COMPANY relational database schema .

Write relational algebra


expression for the following queries: (underline attribute represents Primary Key of the relation) (4 M)

EMPLOYEE (Fname, Minit, Lname, Ssn, Bdate, Address, Sex, Salary, Super_ssn, Dno)

DEPARTMENT (Dname, Dnumber, Mgr_ssn, Mgr_start_date)

DEPT_LOCATIONS (Dnumber, Dlocation)

PROJECT (Pname, Pnumber, Plocation, Dnum)

WORKS_ON (Essn, Pno ,Hours)

DEPENDENT (Essn ,Dependent_name ,Sex , Bdate ,Relationship)

1. Retrieve the name and address of all employees who work for the ‘Research’ department.

2. Find the names of employees who work on all the projects controlled by department number 25.

3. Make a list of project numbers for projects that involve an employee whose last name is ‘Smith’, either as a
worker or as a manager of the department that controls the project.

d4.Find the name of employee who is having maximum salary.

1. Retrieve the name and address of all employees who work for the ‘Research’
department.

2. Find the names of employees who work on all the projects controlled by
department number 15.

3. Make a list of project numbers for projects that involve an employee whose last
name is ‘Smith’, either as a worker or as a manager of the department that
controls the project.
2.b) Consider the following relations:

Student(snum: integer, sname: string, major: string, level: string, age: integer)

Class(name: string, meets at: string, room: string, fid: integer)

Enrolled(snum: integer, cname: string)

Faculty(fid: integer, fname: string, deptid: integer) (4 M)

The meaning of these relations are for example, Enrolled has one record per student-cl ass pair such that
the student is enrolled in the class.

Write the following queries in SQL. No duplicates should be printed in any of the answers.

1. Find the names of faculty members who teach in every room in which some class is taught.

2. Find the names of faculty members for whom the combined enrollment of the courses that they teach is
more than 5.

For each level, print the level and the average age of students for that level.

SELECT level, AVG(age) AS average_age


FROM Student
GROUP BY level;
4. For each faculty member that has taught classes only in room R128, print the faculty
member’s name and the total number of classes she or he has taught.

SELECT F.fname, COUNT(*) AS total_classes_taught


FROM Faculty F
JOIN Class C ON F.fid = C.fid
WHERE C.room = 'R128'
GROUP BY F.fname
HAVING COUNT(DISTINCT C.room) = 1;

You might also like