Task 1: Consider the following relational schema • Employee (EmpID, Name, Dob, Gender, Doj, Designation, Basic_pay, DNo); Gender must take value ‘M’ or ‘F’. • Dept (DNo, DName); • SkillSet (SkillNo, Description, Charge_Outrage); • EmpSkills (EmpID, SkillNo); • Project (PNo, PName, Start_Date, End_Date, Project_Manager_ID); Project Number must start with ‘P’. • Works (EmpID, PNo, Date_Worked_On, Intime, Outtime); Questions 1. Develop DDL to implement the above schema specifying appropriate data types for each attributes and enforcing primary key, check constraints and foreign key constraints. 2. Develop a SQL query to list the details of staff who earn the AVG basic pay of all staff. 3. Develop a SQL query to list the details of staff who have skills with a charge outrate greater than 60 per hour. 4. Develop a SQL query that will keep track of the department number, department name, the number of employees in the department and total basic pay expenditure for the department and store result in a temporary table. 5. Develop a SQL query to list the details of Depts which has more than 3 employees working in it. 6. Develop a SQL query to list the details of employees who have 2 or more skills but not more than 4
Question
Task 1: Consider the following relational schema • Employee (EmpID, Name, Dob, Gender, Doj, Designation, Basic_pay, DNo); Gender must take value ‘M’ or ‘F’. • Dept (DNo, DName); • SkillSet (SkillNo, Description, Charge_Outrage); • EmpSkills (EmpID, SkillNo); • Project (PNo, PName, Start_Date, End_Date, Project_Manager_ID); Project Number must start with ‘P’. • Works (EmpID, PNo, Date_Worked_On, Intime, Outtime); Questions
- Develop DDL to implement the above schema specifying appropriate data types for each attributes and enforcing primary key, check constraints and foreign key constraints.
- Develop a SQL query to list the details of staff who earn the AVG basic pay of all staff.
- Develop a SQL query to list the details of staff who have skills with a charge outrate greater than 60 per hour.
- Develop a SQL query that will keep track of the department number, department name, the number of employees in the department and total basic pay expenditure for the department and store result in a temporary table.
- Develop a SQL query to list the details of Depts which has more than 3 employees working in it.
- Develop a SQL query to list the details of employees who have 2 or more skills but not more than 4
Solution
Sure, here are the SQL queries for each of the tasks:
- DDL to implement the schema:
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Name VARCHAR(100),
Dob DATE,
Gender CHAR(1) CHECK (Gender IN ('M', 'F')),
Doj DATE,
Designation VARCHAR(100),
Basic_pay DECIMAL(10,2),
DNo INT
);
CREATE TABLE Dept (
DNo INT PRIMARY KEY,
DName VARCHAR(100)
);
CREATE TABLE SkillSet (
SkillNo INT PRIMARY KEY,
Description VARCHAR(100),
Charge_Outrage DECIMAL(10,2)
);
CREATE TABLE EmpSkills (
EmpID INT,
SkillNo INT,
PRIMARY KEY (EmpID, SkillNo),
FOREIGN KEY (EmpID) REFERENCES Employee(EmpID),
FOREIGN KEY (SkillNo) REFERENCES SkillSet(SkillNo)
);
CREATE TABLE Project (
PNo CHAR(10) PRIMARY KEY CHECK (PNo LIKE 'P%'),
PName VARCHAR(100),
Start_Date DATE,
End_Date DATE,
Project_Manager_ID INT
);
CREATE TABLE Works (
EmpID INT,
PNo CHAR(10),
Date_Worked_On DATE,
Intime TIME,
Outtime TIME,
PRIMARY KEY (EmpID, PNo, Date_Worked_On),
FOREIGN KEY (EmpID) REFERENCES Employee(EmpID),
FOREIGN KEY (PNo) REFERENCES Project(PNo)
);
- SQL query to list the details of staff who earn the AVG basic pay of all staff:
SELECT * FROM Employee
WHERE Basic_pay = (SELECT AVG(Basic_pay) FROM Employee);
- SQL query to list the details of staff who have skills with a charge outrate greater than 60 per hour:
SELECT E.* FROM Employee E
JOIN EmpSkills ES ON E.EmpID = ES.EmpID
JOIN SkillSet S ON ES.SkillNo = S.SkillNo
WHERE S.Charge_Outrage > 60;
- SQL query that will keep track of the department number, department name, the number of employees in the department and total basic pay expenditure for the department and store result in a temporary table:
CREATE TEMPORARY TABLE DeptExpenditure AS
SELECT D.DNo, D.DName, COUNT(E.EmpID) AS NumEmployees, SUM(E.Basic_pay) AS TotalBasicPay
FROM Dept D
JOIN Employee E ON D.DNo = E.DNo
GROUP BY D.DNo, D.DName;
- SQL query to list the details of Depts which has more than 3 employees working in it:
SELECT D.* FROM Dept D
JOIN Employee E ON D.DNo = E.DNo
GROUP BY D.DNo
HAVING COUNT(E.EmpID) > 3;
- SQL query to list the details of employees who have 2 or more skills but not more than 4:
SELECT E.* FROM Employee E
JOIN EmpSkills ES ON E.EmpID = ES.EmpID
GROUP BY E.EmpID
HAVING COUNT(ES.SkillNo) BETWEEN 2 AND 4;
Similar Questions
Consider following schema and write query for given statementEmp (eid,ename,city,dname,salary) Project(eid,pid,pname,location)Create tables with Primary Key, foreign key constraints in given schemas.(1) Display name of employees who belongs to Computer department.(2) Display employee id whose name starts from letter J.(3) Display all details of employees whose salary is from 10000 to 20000.(4) Display name of employees who are having maximum salary.(5) Display name of employees whose salary is higher than average salary of the employee.(6) Display name of employees whose project id is 3 and location is Mumbai
Consider the three relations given below.Note that the primary keys are underlined.employees (employee_num, employee_name, contact_num, salary)taskAssignment (employee_num, task_num, task_duration)tasks (task_num, location)Select the list of possible foreign key(s) for the given relations.employee_numemployee_num, task_numtask_numtask_num, task_duration
We have following relationEMP(empo,ename,jobtitle,manager_no,hiredate,salary,deptno)DEPT (deptno, dname,location)1) Find employees whose name start with letter A or letter a.2) Find the employees who are working in smith's department.3) Display employees who are getting maximum salary in each department
For given relation:Employee(eid, ename, address,deptname ,salary)Project(eid, pid, pname, location)(1) Display name and salary of employee who is taking maximum salary.(2) Display highest salary department wise and name of employee who is taking thatsalary.(3) Find details of employee who works on a pid equal to 10
1. Create a table called EMP with the following structure. Name Type EMPNO NUMBER (6) ENAME VARCHAR2 (20) JOB VARCHAR2 (10) DEPTNO NUMBER (3) SAL NUMBER (7,2) Allow NULL for all columns except ename and job. 2. Add constraints to check, while entering the empno value (i.e) empno > 100. 3. Define the field DEPTNO as unique. 4. Create a primary key constraint for the table(EMPNO). 5. Write queries to implement and practice constraints.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.