You are on page 1of 7

FAQIHAH SYAZWANI SUBMISSION WEEK4, 23/4/2021

Exercise 1: Introduction to SQL

1. Select all information from SALGRADE table.

2. Select all information from the EMP table.

select *
from EMP;

3. List all employees who have a salary between 1000 and 2000.

select EMPNO, ENAME, SAL


from EMP
where SAL BETWEEN 1000 AND 2000;

select EMPNO, ENAME, SAL


from EMP
where SAL>=1000
and SAL<=2000;
4. List department numbers and names in department name order.

select EMPNO, ENAME


from EMP
order by EName;

5. Display all the different job types.

select JOB
from EMP;
6. List the details of the employees in departments 10 and 20 in alphabetical order of name.

select *
from EMP
where DEPTNO BETWEEN '10' AND '20'
ORDER BY ENAME;

7. List names and jobs of all clerks in department 20.

select ENAME, JOB


from EMP
where DEPTNO = 20;

8. Display all employees names which have TH or LL in them.

select ENAME
from EMP
where ENAME LIKE '%TH%'
OR ENAME LIKE '%LL%';

9. List the following details for all employees who have a manager.

select MGR, ENAME


from EMP
WHERE MGR IS NOT NULL;
10. Display name and total renumeration for all employees.

select ENAME, SAL, COMM, (SAL+COMM)"Renumeration"


from EMP;
11. Display all employees who were hired during 1983.

select ENAME
from EMP
where HIREDATE LIKE '%1983%'

12. Display name, annual salary and commission of all salespeople whose monthly salary is greater
than their commission. The output should be ordered by salary, highest first.
If two or more employees have the same salary sort by employee name, within the highest
salary order.

select ENAME, (12*SAL+COMM)"ANNUAL SALARY", COMM


from EMP
WHERE SAL>COMM
ORDER BY SAL;
13. Select data as displayed:

Who, what and when


------------------------------------------------------------------------------------------------------
SMITH HAS HELD THE POSITION OF CLERK IN DEPT 20 SINCE 17-DEC-80
ALLEN HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 20-FEB-81
WARD HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 22-FEB-81
JONES HAS HELD THE POSITION OF MANAGER IN DEPT 20 SINCE 02-APR-81
MARTIN HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 28-SEP-81
BLAKE HAS HELD THE POSITION OF MANAGER IN DEPT 30 SINCE 01-MAY-81
CLARK HAS HELD THE POSITION OF MANAGER IN DEPT 10 SINCE 09-JUN-81
SCOTT HAS HELD THE POSITION OF ANALYST IN DEPT 20 SINCE 09-DEC-82
KING HAS HELD THE POSITION OF PRESIDENT IN DEPT 10 SINCE 17-NOV-81
TURNER HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 08-SEP-81
ADAMS HAS HELD THE POSITION OF CLERK IN DEPT 20 SINCE 12-JAN-83
JAMES HAS HELD THE POSITION OF CLERK IN DEPT 30 SINCE 03-DEC-81
FORD HAS HELD THE POSITION OF ANALYST IN DEPT 20 SINCE 03-DEC-81
MILLER HAS HELD THE POSITION OF CLERK IN DEPT 10 SINCE 23-JAN-82
14 rows selected

You might also like