You are on page 1of 2

SQL>

SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
2
3

SET PAGESIZE 100


/*********************************
Assignment - Lab 2 Solution
By: <Nahian Aziz>
Lab section: 2B [replace the ?? with one of 1A, 1B, 2A, or 2B]
**********************************/
/*** 1 ***/
/* Write a query to display the last name and salary for
all employees whose salary falls in the range of $2,500
to $2,600 inclusive. Label the columns Poor Employee and
Monthly Salary respectively.*/
SELECT last_name AS "Poor Employee", salary AS "Monthly Salary"
FROM employees
WHERE salary BETWEEN 2500 AND 2600;

Poor Employee
Monthly Salary
------------------------- -------------OConnell
2600
Grant
2600
Himuro
2600
Colmenares
2500
Marlow
2500
Patel
2500
Matos
2600
Vargas
2500
Sullivan
2500
Perkins
2500
10 rows selected.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
2
3
4

/*** 2 ***/
/* Write a query to display the last name and department
number of all employees in departments 60, 70 and 90
in alphabetical order by last name descending. */
SELECT last_name, department_id
FROM employees
WHERE department_id IN (60, 70, 90)
ORDER BY last_name DESC;

LAST_NAME
DEPARTMENT_ID
------------------------- ------------Pataballa
60
Lorentz
60
Kochhar
90
King
90
Hunold
60
Ernst
60
De Haan
90
Baer
70
Austin
60
9 rows selected.

SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
2
3

/*** 3 ***/
/* Write a query to display the last names of all employees
where the third letter of their name is an a. */
SELECT last_name
FROM employees
WHERE last_name LIKE '__a%';

LAST_NAME
------------------------Grant
Grant
Whalen
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
SQL>
2
3
4
5

/*** 4 ***/
/* Write a query to display the first name, last name, salary, and
commission for all employees who earn commissions and have a
last name beginning with the letter S. Sort data in
descending order of salary and commissions. */
SELECT first_name, last_name, salary, commission_pct
FROM employees
WHERE last_name LIKE 'S%'
AND commission_pct IS NOT NULL
ORDER BY salary DESC, commission_pct DESC;

FIRST_NAME
-------------------Patrick
Lindsey
William
Sarath
SQL>
SQL>
SQL>
SQL> SPOOL OFF

LAST_NAME
SALARY COMMISSION_PCT
------------------------- ---------- -------------Sully
9500
.35
Smith
8000
.3
Smith
7400
.15
Sewall
7000
.25

You might also like