Exercises For Practical 7: I) Select From Employee From Employee Where Job - Id 'ST - CLERK' AND Hire - Date '31-DEC-1997'

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Exercises for Practical 7

1) Create the employee table as below and copy the insert statement provided to insert the
records.

_pct nu

insert into employee values(141, 'Trenna','King','TRAJS','6501218009',to_date('17-OCT-


1995','dd-MON-YYYY'),'ST_CLERK',3500,null,124,50);
insert into employee values(142,'Curtis','Loren','CLOREN','6501212994',to_date('29-
JAN-1997','dd-MON-YYYY'),'ST_CLERK',3100,null,124,50);
insert into employee values(149,'Eleni','Grant','EGRANT','65012155922',to_date('29-
JAN-2000','dd-MON-YYYY'),'SA_MAN',10500,.2,100,80);
insert into employee values(174,'Abel','Ellen','AELL','65012553251',to_date('11-MAY-
1996','dd-MON-YYYY'),'SA_REP',1100,.3,149,80);
insert into employee values(176,'Jonathan','Taylor','JTAYLOR','3215456654',to_date('24-
MAR-1998','dd-MON-YYYY'),'SA_REP',8600,.2,149,80);
insert into employee values(178,'Kimberly','Grant','Kgrant','4556621455',to_date('24-
MAY-1999','dd-MON-YYYY'),'SA_REP',7000,.15,149, null);

2) Once you complete the above steps, write the sql select statement for each of the questions
below:-

i) Show all data of the programmers who have been hired after the year 1997.

Select * from employee from employee


Where job_id=’ST_CLERK’ AND hire_date > ’31-DEC-1997’;
ii) Show the last name, job, salary, and commission of those employees who earn
commission. Sort the data by the salary in descending order.

Select l_name, job_id, salary, commission_pct from employee


Where commission_pct is not null,
Order by salary desc;

iii) Show the employees that have no commission with a 10% raise in their salary
(round off the salaries).

Select l_name, salary,ROUND(salary*1.10) “New salary”


From employee,
Where commission _pct is null;

iv) Show the last names of all employees together with the number of years that they
have been employed.
Select l_name, TRUNC((SYSDATE-HIRE_DATE)/365.25) “YEARS”
FROM EMP;
**SYSDATE= current date

v) Show those employees that have a name starting withJ,K,L, orM.


Select l_name
From employee
Where SUBSTR(l_name,1,1) IN (‘J’,’K’,’L’,’M’);

vi) Show all employees, and indicate with “ Yes” or “ No” whether they receive a
commission.

Select l_name, salary, DECODE( COMMISSION_PCT, NULL, ‘NO’,


‘YES’)COMMISSION
FROM EMPLOYEE;
**IF commission is null = NO, if not null is YES.
** decode change null to no and not null to yes.

vii) Show all employees who were hired in the first half of the month (before the 16th
of the month).

SELECT L_NAME, HIRE_DATE


FROM EMPLOYEE
WHERE TO CHAR(HIRE_DATE,’DD’)<16;

viii) Show the names, salaries, and the number of dollars (in thousand s) that all
employees earn.

SELECT L_NAME, SALARY, TRUNC(SALARY,-3)/1000 “THOUSANDS”


FROM EMPLOYEE;
ix) Create an anniversary overview based on the hire date of the employees. Sort the
anniveraries in ascending order.

SELECT L_NAME, TO_CHAR(HIRE_DATE, ‘MONTH DD’)


“ANNIVERSARIES”
FROM EMPLOYEE
ORDER BY ANNIVERSARIES;

You might also like