Advanced DBMS
Advanced DBMS
BS-CS 4th-B
Lab Task#03
ii. The HR department wants you to display the first_name, last_name , salary
and (salary+(salary*commission_pct)) as Net Salary of employees whose Net
Salary is in the range 10000 and 15000 and who gets atleast a percentage of
commission_pct.
ii. The HR department wants to see the employees that do not belong to any
department specifically. You need to display the employee_id, first_name,
last_name and salary of employees whose department_id is null.
select employee_id,first_name,last_name,salary
from employees
where department_id is null;
iv. Write a query to display the name (first_name, last_name) and hire date for
all employees who were hired in 1987
v. Write a query to display the first_name of all employees who have both "b"
and "c" in their first name.
vi. Write a query to display the last name, job, and salary for all employees
whose job is that of a Programmer or a Shipping Clerk, and whose salary is not
equal to $4,500, $10,000, or $15,000.
select first_name,job_id,salary
from employees
where (job_id like '%PROG' OR JOB_ID LIKE '%CLERK')
and salary not in (4500,10000,15000);
vii. Write a query to display the last name of employees whose names have
exactly 6 characters.
Mahnoor Zahoor (UW-23-CS-BS-107)
select last_name
from employees
where length(last_name)=6;
ix. The company wants to donate 15% salary of each employee. To see the record
write a query to display the name (first_name, last_name),salary and PF (15% of
salary) of all employees.
x. Write a query in SQL to display all the information of employees whose salary
is in the range of 8000 and 12000 and commission is not null or department
number is except the number 40, 120 and 70 and they have been hired before
June 5th, 1987.
xi. Write a query in SQL to display the full name (first and last), job id and date
of hire for those employees who was hired during November 5th, 2007 and July
5th, 2009.
xiii. Write a query in Sql to display the full name (first and last name), salary,
and manager number for those employees who is not working under a manager.
ii. Create a report that displays the last name and department number for
employee number 176. Run the query.
vi. The HR department wants you to write a query to find the employee_id,
last_name, job_id, department_id other than the department with id 90. Hint <>
is the symbol for !=.
This query selects employees whose job_id is NOT 'IT_PROG', 'ST_CLERK', or 'SA_REP'.
WHERE CustomerName LIKE 'a%' Finds any values that start with "a"
WHERE CustomerName LIKE '%a' Finds any values that end with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in
any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in
WHERE ContactName LIKE 'a%o' Finds any values that start with "a"
Mahnoor Zahoor (UW-23-CS-BS-107)
The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.
There are two wildcards often used in conjunction with the LIKE operator:
• % - The percent sign represents zero, one, or multiple characters
• The underscore represents a single character
SELECT last_name
FROM employees
WHERE manager_id IS NULL;
Mahnoor Zahoor (UW-23-CS-BS-107)
This selects employees earning at least $10,000 AND having "MAN" in their job_id.
This selects employees earning at least $10,000 OR having "SA" in their job_id.
Rules of Precedence
The condition salary > 15000 applies only to 'AD_PRES', not 'SA_REP'.
iii. The HR department wants to know the senior most employee details.
SELECT *
FROM employees
WHERE hire_date = (SELECT MIN(hire_date) FROM employees);
v. The HR wants to see the annual salary of all employees starting by the highest
paid employee.
This sorts everything by column1 first and then by column2 whenever the
column1 fields for two rows are equal.
It sorts by department_id first, and within each department, employees are sorted by salary in
descending order.