Student Name : Abdulaziz Bakhsh
Student ID : 1543123
Database Lab 3
Lab. Activity – 01:
Q : Create a query to display the last name and salary of employees earning more than $12,000.
Code : select LAST_NAME, SALARY
from employees
where SALARY > 12000;
Q : Display the last name and salary for all employees whose salary is not in the range of $5,000 and
$12,000.
Code : select LAST_NAME, SALARY
from employees
where SALARY not between 5000 and 12000;
Q : Display the last name and hire date of every employee who was hired in 1994.
Code : SELECT last_name, hire_date
FROM employees
WHERE hire_date LIKE '%94';
// NO DATA BECOUCE THERE WAS NO ONE HIRED IN 1994 //
Q : Display the last name and job title of all employees who do not have a manager.
Code : select LAST_NAME, JOB_ID job_title
from employees
where MANAGER_ID is null ;
Lab. Activity – 02:
Q : Display the last name, salary, and commission for all employees who earn commissions. Sort data in
descending order of salary and commissions.
Code : select last_name, salary, commission_pct
from employees
where commission_pct is not null
order by salary, commission_pct DESC;
Q : List the last name and salary of employees who earn between $5,000 and $12,000, and are in
department 20 or 50. Label the columns Employee and Monthly Salary, respectively.
Code : select last_name "Employee", salary "Monthly Salary"
from employees
where (salary between 5000 and 12000) and department_id in (20,50);
Q : Write a SQL statement to display either those orders which are not issued on date 2012-09-10 and
issued by the salesman whose ID is 505 and below or those orders which purchase amount is 1000.00
and below.
Code : SELECT *
FROM orders
WHERE NOT ((ord_date ='2012-09-10'
AND salesman_id <= 505)
OR purch_amt <= 1000.00);
Practice Overview Questions
Q1: Create a report that produces the following for each employee:< employee last name> earns <
salary>monthly but wants < 3 times salary> . Label the column Dream Salaries.
Code: select last_name||' earns $'||salary||' monthly but wants $'||salary*3
"Dream Salary"
from employees;
Q2: Write a query that displays the last name (with the first letter uppercase and all other letters
lowercase) and the length of the last name for all employees whose name starts with the letters J, A, or
M. Give each column an appropriate label. Sort the results by the employees’ last names.
Code: select initcap(last_name) "Name", length(last_name) "Length of Name"
from employees
where last_name like 'J%' or last_name like 'A%' or last_name like 'M%'
order by last_name;
Q3: The HR department needs a report to display the employee number, last name, salary, and salary
increased by 15.5% (expressed as a whole number) for each employee. Label the column New Salary.
Code: select employee_id, last_name, salary, salary+(salary*15.5/100) "New
Salary"
from employees;