Consider the following database schema (primary keys are bolded and underlined):
ID: 3705348 • Letter: C
Question
Consider the following database schema (primary keys are bolded and underlined): Employees(elD; integer, eName: string, age: integer, salary: real) Works(elD: integer, dName: string, startedDate: date, ended: date) Departments(dName: string, budget: real, managerEID: integer) The meaning of these relations is straightforward, for example, the table Works has one record per employee-department pair, such that an employee works for a department for a specific period of time. There are three foreign keys for this database: The attribute elD of the relation Works that references the relation Emplovees The attribute 4Name of the relation Works that references the relation Departments rences the relation The attribute managerEID of the relation Departments that references the relation Employees Write the following queries in SQL. No duplicates should be printed in any of the answers. You should use the SQL keyword DISTINCT only when necessary. Also, the creation of temporary tables is not allowed, i.e., for each question, you must write exactly one SQL statement. Note: You MUST denote the number of each query before your answer. 1. Retrieve the name and budget of every department 2. Retrieve the name and budget of every department with a budget greater than S100,000.00 3. Retrieve the name of every department along with its manager name. 4. Retrieve the name and budget of every department that has more budget than the Data Mining department. Note that Data Mining is a department name. 5. Retrieve the names of each employee who works for both departments of Data Warehouse and the Data Mining. Note that e and Data Mining are 6. Find the name of the departament with the largest amount of budgetExplanation / Answer
The SQL for the problem are as follows:
1. Retrieve the name and budget of every department:
Select dName, budget from Departments.
2. Retrieve the name and budget of every department with budget > $100,000.00
Select dName, budget from Departments where budget > 100000.00
3. Retrieve the of every department along with its manager name:
Select dName , eName from Departments dp inner join Employees e on dp.ManagerEID = e.eID
4. Retrieve the name and budget of every department that has more budget than Data Mining Department.
Select dName, budget from Departments where budget > (Select budget from Departments where dName = 'Data Mining Department')
5.Retrieve the names of each employee who works for both departments of Data Warehouse and data mining.
Select Distinct eName from Employees e inner join Works w on w.eID = e.eID where w.dName in ('Data Warehouse','Data Mining')
6. Find the name of the department with largest amount of budget
Select dName from Departments where budget >= (Select max(budget) from Departments)