SQL Commands
SQL Commands
7. Display the names of all employees who are working in department number 10.
8. Display the names of all employees working as clerks and drawing a salary
9. Display employee number and names for employees who earn commission.
select empno, ename from emp where comm is not null and comm>0;
11.Display the names of employees who are working as clerk, salesman or analyst
(or)
and sal>3000;
12.Display the names of employees who are working in the company for the past
5 years.
13.Display the list of employees who have joined the company before 30th June 90
1990’;
show user;
(‘CLERK’,’SALESMAN’,’ANALYST’);
20.Display employee names for employees whose name ends with alphabet.
21.Display the names of employees whose names have second alphabet A in their
names.
length.
(or)
select * from emp minus (select * from emp where empno in (select
(or)
select * from emp where empno not in (select mgr from emp where
(or)
select * from emp e where empno not in (select mgr from emp where
e.empno=mgr)
24.Display the names of employees who are not working as SALESMAN or CLERK
or ANALYST.
(‘CLERK’,’SALESMAN’,’ANALYST’);
25.Display all rows from EMP table. The system should wait after every screen full
of information.
36.Display the names of employees in order of salary i.e. the name of the
39.Display empno, ename, deptno, and sal. Sort the output first based on name
40.Display the name of the employee along with their annual salary (Sal * 12).
The name of the employee earning highest annual salary should appear first.
12*(sal+nvl(comm,0)) desc;
41.Display name, Sal, hra, pf, da, total Sal for each employee. The output should
be in the order of total Sal, hra 15% of Sal, da 10% of sal, pf 5% of sal total
42. Display dept numbers and total number of employees within each group.
43.Display the various jobs and total number of employees with each job group.
46.Display the various jobs and total salary for each job.
47.Display each job along with minimum sal being paid in each job group.
48.Display the department numbers with more than three employees in each dept.
49.Display the various jobs along with total sal for each of the jobs where total sal
50.Display the various jobs along with total number of employees in each job. The
output should contain only those jobs with more than three employees.
52.Display the employee number and name of employee working as CLERK and
53.Display the names of the salesman who earns a salary more than the highest
54.Display the names of clerks who earn salary more than that of James of that of
select ename from emp where job='CLERK' and sal<(select sal from
emp where ename='SCOTT') and sal>(select sal from emp where
ename='JAMES');
55.Display the names of employees who earn a Sal more than that of James or
56.Display the names of the employees who earn highest salary in their respective
departments.
57.Display the names of employees who earn highest salaries in their respective
job groups.
select * from emp e where sal in
(or)
select ename from emp where deptno in (select deptno from dept
where dname=”ACCOUNTING”);
60.Display the job groups having total salary greater then the maximum salary for
managers.
select job, sum(sal) from emp group by job having sum(sal) >
select ename, sal, deptno from emp e where deptno=10 and sal >
(or)
from the following string ‘Oracle’ i.e. the output should be ‘rac’.
maintenance corporation’.
translate function).
72.Display the information from EMP table. Wherever job ‘manager’ is found it
73.Display empno, ename, deptno from EMP table. Instead of display department
e.deptno = d.deptno;
select floor(months_between(sysdate,'15-aug-1947'))
select job from emp where deptno=10 and job in(select job from emp
where deptno=20);
(or)
select job from emp where deptno=10 intersect select job from emp
where deptno=20;
jobs.
select distinct(job) from emp where deptno=10 and job in(select job
94.Display those employees whose salary greater than his manager salary.
empno=e.mgr);
95.Display those employees who are working in the same dept where his manager
is working.
96.Display those employees who are not working under any manger.
97.Display grade and employees name for the dept no 10 or 30 but grade is not 4,
98.Update the salary of each employee by 10% increments that are not eligible for
commission.
99.Delete those employees who joined the company before 31-dec-82 while there
100.Display employee name, job, deptname, location for all who are working as
managers.
101.Display those employees whose manager names is Jones, and also display
102.Display name and salary of ford if his Sal is equal to high Sal of his grade.
select ename,sal from emp e where ename='FORD' and sal=(select hisal from salgrade
where grade=(select grade from salgrade where e.sal>=losal and e.sal<=hisal));
103.Display employee name, his job, his dept name, his manager name, his grade
break on deptno;
select d.deptno, e.ename, e.job, d.dname, m.ename, s.grade from
emp e, emp m, dept d, salgrade s where e.deptno=d.deptno and e.sal
between s.losal and s.hisal and e.mgr=m.empno order by e.deptno;
104.List out all the employees name, job, and salary grade and department name
for every one in the company except ‘CLERK’. Sort on salary display the
highest salary.
select empno, ename, sal, dname, grade from emp e, dept d, salgrade s
where e.deptno=d.deptno and e.sal between s.losal and s.hisal and
e.job<>'CLERK' order by sal;
105.Display employee name, his job and his manager. Display also employees who
107.Display the name of those employees who are getting highest salary.
emp);
minimum.
emp);
110.Display dname where at least 3 are working and display only dname.
select dname from dept where deptno in
111.Display name of those managers name whose salary is more than average
salary of company.
select ename, sal from emp where empno in(select mgr from emp) and
112.Display those managers name whose salary is more than an average salary of
his employees.
select ename, sal from emp e where empno in(select mgr from emp)
113.Display employee name, Sal, comm and net pay for those employees whose
net pay are greater than or equal to any other employee salary of the
company?
114.Display those employees whose salary is less than his manager but more than
select * from emp e where sal<(select sal from emp where empno =
115.Display all employees names with total Sal of company with employee name.
Select ename,
117.Find out the number of employees whose salary is greater than there manager
salary?
select count(*) from emp e where sal>(select sal from emp where
empno=e.mgr);
118.Display those manager who are not working under president but they are
select * from emp e where mgr in(select empno from emp where
ename<>'KING');
deptno=d.deptno);
120.Delete those records from EMP table whose deptno not available in dept table?
delete from emp where deptno not in(select deptno from dept);
121.Display those earners whose salary is out of the grade available in Sal grade
table?
122.Display employee name, Sal, comm. and whose net pay is greater than any
123.Display name of those employees who are going to retire 31-dec-99. If the
126.Display those employees who joined in the company in the month of DEC?
characters of salary?
select substr(hiredate,0,2)||substr(sal,length(sal)-1,2) from emp;
select concat( substr(hiredate,0,2), substr(sal,length(sal)-1,2) ) from
emp;
130.Display those employees whose 10% of salary is equal to the year of joining?
select * from emp where deptno in(select deptno from dept where
dname in('SALES','RESEARCH'));
133.Display those employees who joined the company before 15th of the month?
to_char(hiredate,'mon')||'-'||to_char(hiredate,'yyyy')));
than 3?
delete from emp where deptno in(select deptno from emp group by
135.Delete those employees who joined the company 21 years back from today?
select * from emp where round((sysdate-hiredate)/365)>21;or
select * from emp where (to_char (sysdate, 'yyyy')-to_char
(hiredate ,'yyyy') )>21;
138.Count the no of employees who are working as manager (use set operation)?
select count(*) from emp where empno in(select mgr from emp);
139.Display the name of then dept those employees who joined the company on
140.Display those employees whose grade is equal to any number of Sal but not
141. Display the manager who is having maximum number of employees working
under him?
number of dollars?
from emp;
143.Produce the output of the EMP table “EMPLOYEE_AND_JOB” for ename and job?
144.List all employees with hire date in the format ‘June 4 1988’?
145.Print a list of employees displaying ‘Less Salary’ if less than 1500 if exactly
1500 display as ‘Exact Salary’ and if greater than 1500 display ‘More Salary’?
146.Write query to calculate the length of employee has been with the company?
147.Given a String of the format ‘nn/nn’ verify that the first and last 2 characters
are numbers. And that the middle characters is ‘y’ print the expressions ‘Yes’ if
valid ‘No’ of not valid use the following values to test your solution
148.Employees hire on 15th of any month are paid on the last Friday of that month.
Those hired after 15th are paid the last Friday of the following month. print a
list of employees their hire date and first pay date sort those whose Sal
contains first digits of their dept.
149.Display those mangers who are getting less than his employees Sal.
Select empno from emp e where sal<any(select sal from emp where
mgr=e.empno);
150.Print the details of all the employees who are sub ordinate to Blake.
ename='BLAKE');
152.Display those employees whose manger name is Jones and also with his
manager name.
define emp_ann_sal=(sal+nvl(comm,0))*12;
154.Use the variable in a statement which finds all employees who can earn 30,000
a year or more.
select * from emp where &emp_ann_sal>30000;
155.Find out how many mangers are there with out listing them.
Select count (*) from EMP where empno in (select mgr from EMP);
156.Find out the avg sal and avg total remuneration for each job type remember
group by job;
count(empno)=(count(distinct(empno)));
158.List out the lowest paid employees working for each manager, exclude any
groups where min sal is less than 1000 sort the output by sal.
159.list ename, job, annual sal, deptno, dname and grade who earn 30000 per year
160.find out the job that was failed in the first half of 1983 and the same job that
was failed during the same period on 1984.
161.find out the all employees who joined the company before their manager.
empno=e.mgr);
162.list out the all employees by name and number along with their manager’s
name and number also display ‘No Manager’ who has no manager.
163.find out the employees who earned the highest Sal in each job typed sort in
select * from emp e where sal =(select max(sal) from emp where
job=e.job);
164.find out the employees who earned the min Sal for their job in ascending
order.
find out the most recently hired employees in each dept order by hire date
166.display ename, sal and deptno for each employee who earn a Sal greater than
169.In which year did most people join the company. Display the year and number
of employees
to_char(hiredate,'yyyy');
171.Write a query of display against the row of the most recently hired employee.
172.display employees who can earn more than lowest Sal in dept no 30
deptno=30);
173. find employees who can earn more than every employees in dept no 30
175. find out avg sal and avg total remainders for each job type
If the pay day is next Friday after 15th and 30th of every month. What is the
next pay day from their hire date for employee in emp table
your company to have a review after 9 months the joined date (and of 1st of
next month after 9 months) how many days from today your employee has to
wait for a review
179. Display employee name and his sal whose sal is greater than highest avg of
dept no
181. Display the half of the enames in upper case and remaining lower case
select concat ( upper ( substr ( ename, 0 , length (ename)/ 2) ),
lower (substr (ename, length(ename) / 2+1, length(ename) )) ) from
emp;
182.display the 10th record of emp table without using group by and rowed
183.Delete the 10th record of emp table.
184.Create a copy of emp table.
197.I want to give a validation saying that sal cannot be greater 10,000(note give a
198.For the time being I have decided that I will not impose this validation. My
199. My boss has changed his mind. Now he doesn’t want to pay more than
201. Oh! This column should be related to empno. Give a command to add this
constraint
203. This dept no column should be related to deptno column of dept table
references dept(deptno);
204. Create table called as new emp. Using single command create this table as well
205. Create table called as newemp. This table should contain only empno,ename,
dname
d where e.deptno=d.deptno;
206.Delete the rows of employees who are working in the company for more than 2
years.
working.
e.deptno=d.deptno;
d.deptno;
213.Display the department name along with total salary in each department.
215. Alter table emp1 add constraint emp1_deptno foreign key(deptno) references
dept(deptno)
217.Insert into emp without giving any further commands move to another client
system and log into the same user give the following command
219.Go to your fist system and give commit come back to the second system and