National University of Computer and Emerging Sciences, Lahore Campus
Course: Database Systems
Program: BS(Computer Science)
Instructor: Muhammad Ishaq Raza
Practice Problem: SQL (4)
Question 1: Use the two relations given below to write the following queries in SQL:
EMP (SSN, FirstName, LastName, Title, Salary, DeptId, MgrId)
DEPT (Did, DepartmentName, TotalBudget)
Foreign Keys: DeptId references DEPT.Did and MgrId references EMP.SSN
1. Find the name, total budget of departments in which the total salary of all people working in that department
exceeds the total budget of the department.
2. Find the first and last name of employees whose salary is greater than the salary of their manager.
3. Find name of departments that does not have any employees with title ”Vice President” working in them.
Question 2: Consider the following database schema of computer products:
Computer (maker, model, category)
Model (num, speed, ram, hd, price)
Maker (name, address, phone)
Where
• maker indicates the manufacturer of the computer;
• category takes values such as ‘desktop’, ‘laptop’, ‘server’;
• maker and model attributes are foreign keys;
Express following queries in SQL:
1. Find all the makers who make at most one model or don’t make any model.
2. Find all desktop models with the highest speed, and return them along with their makers.
3. Display maker, model_count of all the makers who make at least three different desktop models.
Page 1 of 1