(Pucit) : Punjab University Collefe of Information Technology Database Systems Assignment 2
(Pucit) : Punjab University Collefe of Information Technology Database Systems Assignment 2
(Pucit) : Punjab University Collefe of Information Technology Database Systems Assignment 2
(PUCIT)
Database Systems Assignment 2
CS Morning Fall-19
Due Date: Monday, 05-04-2021
Instructions:
Plagiarism will not be tolerated and will result in ZERO.
Solve all the Queries.
1. Write an SQL query to fetch the different projects available from the EmployeeSalary
table.
2. Write an SQL query to find the maximum, minimum, and average salary of the
employees.
Select MAX(e.Salary), MIN(e.Salary), AVG(e.Salary)
From EmployeeSalary e, EmployeeDetails d
Where e.Emp_ID = d.Emp_ID
3. Write an SQL query to find the employee id whose salary lies in the range of 9000 and
15000.
Select Emp_ID
From EmployeeSalary
Where Salary BETWEEN 9000 AND 15000
4. Write an SQL query to fetch those employees who live in Toronto and work under
manager with ManagerId – 321.
Select Emp_ID, e.Full_Name
From EmployeeDetails d , EmployeeSalary e
Where e.Emp_ID = d.Emp_ID
AND d.city = ‘Toronto’
AND ManagerId = 321
5. Write a Query to display all the records from both the tables which are not same.
Select *
From EmployeeSalary e, EmployeeDetails d
Where e.* <> d.*
6. Write a Query to display all the records from EmployeeDetails Table only which are not
present in EmployeeSalary Table.
Select d.*
From EmployeeDetails d, EmployeeSalary e
Where d.* <> e.*
7. Calculate the remainder of a salary after it is divided by 500, name it as “total salary” for
all employees whose job title is “manager” and sort it by “total salary”.
Select MOD(Salary,500) AS “total salary” ,
From EmployeeSalary
Where job = ‘manager’
ORDER BY ‘total salary’
8. Display the emp no, name, manger no, salary, hire date of employees and “New Date”
after adding 7 months in hire date.
Select Emp_ID, d.Full_Name, d.Manager_ID, e.Salary, d.Date_Joining,
ADD_MONTH(Date_Joining, 7)AS “New Date”
From EmployeeDetails d, EmployeeSalary e
Where e.Emp_ID = d.Emp_ID
9. Display the employees whose salary is more than 3000 after giving 25% increment.
Select Emp_ID, d.Full_Name
From EmployeeDetails d, EmployeeSalary e
Where e.Emp_ID = d.Emp_ID
AND (Salary * 0.25) > 3000
10. Write an SQL query to fetch all those employees who work on Project other than P1.
Select Emp_ID, d.Full_Name
From EmployeeDetails d, EmployeeSalary e
Where e.Emp_ID = d.Emp_ID
AND e.Project <> ‘P1’
11. Write an SQL query to fetch the employees whose name begins with any two characters,
followed by a text “hn” and ending with any sequence of characters.
12. Write an SQL query to fetch records that are present in one table but not in another table.
13. Write an SQL query to fetch the employee full names and replace the space with ‘-’.
14. Write an SQL query to fetch the position of a given character(s) in a field.
15. Write an SQL query to display both the EmpId and ManagerId together.
16. Write a query to fetch only the first name(string before space) from the FullName column
of the EmployeeDetails table.
17. Write an SQL query to find the count of the total occurrences of a particular character –
‘n’ in the FullName field.
18. Fetch all the employees who are not working on any project.
Worker (Worker_ID, First_Name, Last_Name, Salary, Joining_Date, Department)
Bonus (Worker_ID, Bonus_Date, Bonus_Amount)
Title (Worker_ID, Worker_Title, Affected_From)
19. Write an SQL query to print the FIRST_NAME from Worker table after removing
white spaces from the right side.
20. Write an SQL query to print the DEPARTMENT from Worker table after removing
white spaces from the left side.
21. Write an SQL query to print the FIRST_NAME from Worker table after replacing ‘a’
with ‘A’.
22. Write an SQL query to print the FIRST_NAME and LAST_NAME from Worker table
into a single column COMPLETE_NAME. A space char should separate them.
23. Write an SQL query to print details of the Workers who are also Managers.
24. Write an SQL query to show only odd rows from a table.
25. Write an SQL query to show only even rows from a table.
Salary
Title Sal
Elect. Eng 40000
Programmer 24000
Employee
ASG
E1 P1 Manager 12
E2 P1 Analyst 24
E2 P2 Analyst 8
E3 P3 Consultant 24
E3 P4 Engineer 16
E4 P2 Programmer 18
E8 P2 Manager 0
E6 P4 Engineer 36
E7 P1 Engineer 0
PROJ
P1 Instrumentation 150000
P3 CAD/CAM 250000
P4 Maintainence 310000
26. Display the date of the next Friday that is six months from the hire date. The resulting
date should appear as Friday, August 13th, 1999. Order the results by hire date.
27. Display output as Name which will contain 1st 3 letters of employee name and last 3
letters of project name of those employees whose project name length is greater than 5.
28. Display length of those employee name as “Names” whose name start with “M” or
contain “A” and ends with “H” working on project that have budget more than the budget
of Smith or on the project same as Lee.
29. Display budget in terms of “$”, where each $ represents RS.100 of that project whose
project name’s first letter is capital, and their salary is multiple of 20.
30. Select the emane, title, resp but sal greater than SMITH sal, budget greater than Michel’s
budget, project same as John but title not same as Miller and Davis.
Teaching Assistants:
• Fatima Tuz Zahra – bcsf17m540
• Areej Ehsan– bcsf17m512