10 Simple Questions - With One Join
10 Simple Questions - With One Join
(PMS) to store information of their employees, salary, leave and monthly payment of all
employees.
Use below “Alias” for the table joins.
Employee_Info - e
Salary_Info - s
Leave_Info - l
Emp_Leave_Info - el
Emp_Payroll - p
Dept_Info – d
List of Tables for the above given case study:
Employee_Info :- Table used to store the employee information
Salary_Info : Table used to store the salary information
Leave_Info: Table used for storing the leave categories and days allowed
Emp_Leave_Info : Table used to store the information of employees who has taken leaves
Emp_Payroll: Table used to store the monthly payment details.
Dept_Info : Table for storing the department information
Simple Questions:
10 simple questions – with one join
Problem # 1: Write a query to display Employee ID, Employee Name, Department ID and
Department Name of all employees who has a department assigned.
Problem # 2: Write a query to display the Employee ID, Employee Name, Basic Pay of all
employees who are in employee category 'A'
Problem # 3: Write a query to display the Employee ID, Employee Name, Department ID and
Department Name of all employees who has a department assigned and department location is
‘CHENNAI’.
Problem # 4: Write a query to display the employee ID and employee name of the employees who
have not been assigned a department yet.
Problem # 5: Write a query to display the employee ID, employee name and joining date of the
employees who joined before 2005.
Problem # 6: write a query to display employee name and date of joining for all employees.(Date
should be displayed in the format “23/JANUARY/2012” with Alias “ JOINING_DATE” in select statement)
Problem # 7: Write a query to display the employee ID, employee name and joining date of the
employees who joined between Jan 1 2005 and Dec 31’st 2010
Problem # 8: Write a query to display the employee ID, employee name and joining date of the
employees who joined in MARCH.
Problem # 9: Write a query to display all employee names which begins with 'R'.
Problem # 10: Write a query to display the first five employees name in the employee table and the
respective row number (use ROWNUM for identifying the first five records)
Average Questions:
10 average questions – with multiple joins
Problem # 3: Write a query to display the EmployeeID, Employee Name and the total number
of leaves each employee has taken with “Total_Leaves” as alias.
Hint: For Example, if employee “E001” has taken 2 days leave on January and 3 days leave of
February then his total number of leaves will be 5 days. Similarly display the total number of
leaves for all employees.
Problem # 4: Write a query to display the EmployeeID, Employee Name, DOB and Age in Years
without decimals with alias name "Age".
Hint: Formula for age calculation is Age = current date- dob/12, round this to the nearest whole
number.
Problem # 5: Write a query to display employee id, employee name of all employees who
doesn't have LOP amount for the month of APR and year 2012.
Problem # 6: Write a query to display employee name, professional tax, netpay of employees with
employee category 'A'
Problem # 7: Write a query to display employee id, employee name,department id who are having
netpay in the range 10000 - 20000
Problem # 8: Write a query to display employee names whose total deduction is more than 2000 for
the month of APRIL.
Problem # 9: Write a query to display employee id, employee name, department id, department name
of all employees regardless of whether an employee is assigned a department or not.
Problem # 10: Write a query to display Employee ID, Employee Name, Department ID, Years of
Experience and Employee Category of the employees who have availed leaves more than 10 days.
Hint: Use the total_leaves column to check the leave condition for more than ten days.
Complex Questions:
Problem # 1: Write a query to display employee id, employee name and remaining casual
leaves (alias- RemainingLeaves) for the employee with employee id "E002". Based on the total
causal leaves available, subtract the number of causal leaves he has availed to get the
remaining leaves.
Hint: CL – Causal leave.
EMPLOYEE_INFO table has Employee’s leave Category. For example employee “E001” belong to
“X” leave category.
EMP_LEAVE_INFO table has details of number of leaves the employees has availed. For
example, “E001” has availed totally 8 days of causal leave.
LEAVE_INFO table has the Leave Category and number of CL, EL and ML available for the
category. For example, “E001” has category X which has 18 days of total causal leave that he
can avail.
So, E001’s remaining leave would be 10 days. Similarly calculate for E002.
Problem # 2: Write a query to display employee id, employee name and total number of leaves
he can take (hint: with “EligibleLeave” as alias). This should be retrieved for all the employees.
Sum all the EL, ML and EL leaves for the each employee’s category to get the total leaves.
Hint:
EMPLOYEE_INFO table has Employee’s leave Category. For example employee “E001” belong to
“X” leave category.
LEAVE_INFO table has the Leave Category and number of CL, EL and ML available for them. For
example, Employee E001 belongs to X category and he has 18 days of CL and 5 days of EL and
10 days of ML that he can avail.
So, E001’s eligible leave would be 33 days which is sum of all his leaves. Similarly calculate for
all employees.
Problem # 3: Write a Query to display employee id, employee name, department id,
department name, net pay of all employees who have drawn the highest salary (net pay) in the
month of APRIL 2012.
Hint: For example if there are 10 employees where 3 employees have got a salary of 1000 which is the
highest salary of the employee in the month of April all the three records needs to be displayed.
Problem # 4: Write a query to display employee id, employee name, basic pay and tax
percentage for all employees. Use “TaxPercentage” as alias. Display the Tax percentage for all
employees based on the following criteria: (If Basic Pay <= 4000 then tax percentage should be
10%, basic <= 5000 then 20%, basic<=6000 then 30% basic > 6000 then 40%).
Problem # 5: Write a query to display employee name,employee category and basic pay for all
employees based on the following criteria: (Emp_cat 'A' - Basic Pay should be 6000, 'B'-4000,
'C'- 3000, 'D'-2000)
Hint: Use “salary” as alias for the basic pay field.
For example, if there are 3 employees with one having category ‘A’ and other having category
‘D’ and other category ‘C’. Then the query should display the three employees name, category
and the salary will be 6000, 2000 and 1000 for the three employees.