SQL
SQL
7. Display the names of all employees who are working in department number 10?
8. Display the names of all employees workings as clerks and drawing a salary more than
3000?
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 and drawing
a salary more than 3000.
(or)
select ename from emp where job in(clerk,salesman,analyst) and
sal>3000;
14. Display the names of employee who are working in the company fast five years
15. Display the list of wmployees who have joined the company before 30th june 90 or after 31st
dec 90.
17. Display the list of users in your database (using log table)
18. Display the names of all tables from the current user
Show user
31-dec-1990;
21. Display the names of employees whode name starts with alphabet s
22. Display employee names for employees whose name ends with alphabet s
23. Display the names of employees whose names have second alphabet A in their names
24. Display the names of employees whose name is exactly five characters in length
Select ename from emp where length(ename)=5; (or) select ename from emp where
ename like _____;
25. display the names of employees who are not working as managers
26. Select * from emp minus (select * from emp where empno in (select mgr from emp));
27.
(or)
28. Select * from emp where empno not in(select mgr from emp where mgr is not null);
29.
(or)
Select * from emp e where not in(select mgr from emp where e.empno=mgr);
30. Display the ename of employees who are not woeking as salesman or clerk or analyst
31. Display all rows from emp table .the system should wait after every screen full of
information.
41. Display the total salary drawn by analyst working in deptno 40.
42. Display the names of employees in order of salary i.e. the name of the employees earning
lowest salar should appear first.
44. Display the details from emp table in order of emp name.
45. Display empno,ename,deptno and sal.sort the output first based omn name and within name
by deptno and within deptno by sal;
46. 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.
47. Display name,sal,hra,pf,da,total sal for each employee.the output should be in the order o;f
total sal,hra15% of sal,da 10% of sal, pf 5% of sal total salary will be (sal*hra*da)-pf.
49. Display dept numbers and total number of employees within each group.
50. Display the various jobs and total mumber of employees with each job group.
51. Display department numbers and total salary for each department.
52. Display department numbers and maximum salary for each department.
53. Display the various jobs and total salary for each job.
54. Display each job along with minimum sal being paid in each job group.
55. Display the department numbers with more than three employee in each dept.
56. Display the various jobs along with total sal for each of the hobs where total sal is greater
then 40000.
57. 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.
59. Display the employee number and name of employee working as clerk amd earning highest
salary among clerks.
60. Select empno,ename from emp where job=CLERK and sal=(select max(sal) from
emp where hob=CLERK);
61. Display the names of the salesman who earns a salary more than the highest salary of any
clerk.
62. Select ename from emp where job=SALESMAN and sal>(select maz(sal) from
emp where job=CLERK);
63. Display the names of clerks who earn salary more than that of james of that of sal lesser
than that of scott.
64. Select ename from emp were job=CLERK and sal<(select sal from emp where
ename=SCOTT) and sal>(select sal from emp where
ename=JAMES);
65. Display the names of employees who earn a sal more than that of james or that of salary
gteater than that of scott.
Select ename from emp where sal<(select sal from emp where ename=SCOTT) and
sal>(select sal from rmp where ename=JAMES);
66. Display the names of the emploees who earn highest salary in their respective departments.
Select * from emp e where sal=(select max(sal) from emp where deptno=e.deptno);
67. Display the names of employees who earn highest salaries in thir respective job groups.
Select * from emp e where sal in (select max(sal) from emp group by job having
e.job=job);
68. Display the employee names who are working in accountging dept.
Select ename from emp where deptno in(select deptno from dept where
dname=ACCOUNTING);
Select ename from emp where deptno=(select deptno from dept where
loc=CHICAGO);
70. Display the hob groups having total salary greater then the maximum salary for managers.
Selct job,sum(sal) from emp group by job having sum(sal)>(select max(sal) from emp
where job=MANAGER);
71. Display the names of employees from department number 10 with salary greater than that of
any employee working in other departments.
Select ename,sal,deptni from emp e where deptno=10 and sal>any(select sal from
emp where e.deptni!=deptno);
72. Display the names of employees from department number 10 with salaty greater then that of
all employees working in other departments.
Select ename,sal,deptno from emp e where deptno=10 and sal>any(select sal from
emp where e.deptno!=deptno);
76. Find out the length of your name using appropriate function.
(or)
Select concat(ename,empno) from emp;
81. Use appropriate function and extract 3 characters starting from 2 characters from the
following string oracle i.e. the output should be rac.
82. Find the first occurrence of character a from the following string computer maintenance
corporation.
83. Replace every occurrence of alphabet Awith B in the string allens (user translate function).
84. Display the information from emp table wherever job manager is found it should be
displayed as boss(replace function).
85. Display empno,ename,deptno from emp table instead of display department numbers
display the related department name (use decode function).
88. Display current date as 15th august Friday nineteen forty seven.
89. Display the following output for each row from emp table as scott has joined the company on
Wednesday 13th august nineteen ninety.
92. Display the date three months before the current date.
94. Select job from emp where deptno=10 and fob in(select job from emp where
deptno=20); (or)
Select job from emp where deptno=10 intersect select job from emp
where deptno=20;
95. Display the jobs found in department numer 10 and 20 eliminate duplicate jobs.
96. Select distinct(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 job from emp where deptno=20;
98. Select job from emp where deptno=10 minus select job from emp where deptno!=10;
(or)
Select job from emp where deptno=10 and job not in (select job from
emp where deptno<>10);
99. Display the details of those who do not have any person working under them.
Select empno from emp where empno not in(select mgr from emp where mgr is not
null);
100.
101. Select * from emp where sal>=(select losal from salgtade where grade=3) and
102.
deptno from
103.
Display those who are not managers and who are manager any one.
Select * from emp where empno in(select mgr from emp where mgr is not null);
104.
Display tose employees whose name contains not less than 4 chars.
105.
0.
Display those departments whode name start with s while location name wnd with
106.
Select * from emp where mgr=(select empno from emp where ename=JONES);
107.
.
Display those employees whode salary is more than 3000 after giving 20% increment
(or)
110.
111.
Select empno,ename from emp where deptno=(select deptno from dept where
dname=SALES);
112.
Display employee name,deptname,salary and comm. For those sal in between 2000
and 5000 while location is Chicago.
Select empno ,ename,deptno from emp where deprno=(select deptno from dept
where loc=CHICAGO) and sal between 2000 and 5000;
113.
Display those employees whose salaru greater than his manager salary.
Selecr * from emp e where sal>(selecr sal from emp where empno=e.mgr);
114.
Display those employees who are working in the same dept where his manager is
working .
Select * from emp e where deptno=(select deptno from emp where empno=e.mgr);
115.
Display those emplouees who are not working under any manager.
116.
Display grade and employees name for the dept no 10 or 30 but grade is not 4,while
joined the company before 31-dec-82.
118.
Update the salary of each employee by 10% increments that are not eligible for
commission.
119.
Delete those employees who hoined the company before 31-dec-82 while there dept
location is NEW YORK or CHICAGO.
120.
121.
Display those employees whode manager names is jones and also display there
manager name.
122.
Display name and salary of ford if his sal is equal to high sal of his grade.
123. Select ename,sal from emp e where ename=FORD and sal=(select hisal from
salgrade where grade=(select grade from salgrade where
e.sa>=losal and e.sal<=hisal));
124.
Display employee name,his job,his dept name,his manager name,his grade and
make out of an under department wise Break d.deptno;
126.
List out all the employees name ,job,and salar grade and department name for every
one in the company exceptCLERK sort on salary display the highest salary.
128.
Display employee name ,his job and his manager .display also emplyoees who are
without manager.
130.
Select * from emp e where 5>(select count(*) from emp where sal>e.sal) order by sal
desc;
131.
Display the name of those employees who are getting highest salary.
132.
Display those employees whose salary id equal to average of maximum and
minimum.
133.
134.
Display dname where at least 3 are working and display only dname.
Select dname from dept where deptno in(select deptno from emp group by deptno
having count(*)>3);
135.
Display name of those manager name whose salary is more than average ssalary of
company.
Select ename,sal from emp where empno in(select mgr from emp) and sal>(select
avg(sal) from emp);
136.
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) and
e.sal>(select avg(sal) from emp where mgr=e.empno);
137.
Display wmployee 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.
138.
Display those emploiyees whose salary is less than his manager but more than
salary of any other managers.
Select * from emp e where sal<(select sal from emp where empno=e.mgr) and
sal>any (select sal from emp where empno!=e.mgr);
139.
Select * from emp e where 5>(select count(*) from emp where sal<e.sal) order by
sal;
140.
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 cempno=e.mge);
141.
Display those manager who are not working under president but they are working
under any other manager.
Select * from femp e where mge in(select empno from emp where ename KING);
142.
Delete from dept d where 0=(select coountA(A*) from rmp where deptno=d.deptno);
143.
Delete those records frtom emp table whose deptno not available in dept table.
Delete from emp where deptno not in(select deptno from dept);
144.
Display those earners whose salary is out of the grade available in sal grade table.
145.
Display employee name,sal ,comm. and whode net pay is greater than any other in
the company.
146. Selecrt ename,sal ,comm, from emp wher sal+sal*15/100sal*5/100+sal*10/100=(select max(sal+sal*15/100-sal*5/100+sal*10/100) from
emp);
147.
Display name of those employees who are going to retire 31-dec-99. if the maximum
job is period is 18 years.
148.
149.
150.
Display those employees who joined in the company in the companu in the months
of dec.
151.
152.
153.
Display those employees whose first 2 characters from hiredare-last 2 characters of
salary.
154.
Display those employee whose 10% of salary is equal to the year of joining.
155.
Select * from emp where deptno in(select deptno from dept where dname
in(SALES,RESEARCH));
156.
157. Select grade from salgrade where losal<=(select(sal) from emp where
ename=JONES) and hisal>+(select(sal) from emp where
ename=JONES);
158.
Display those employees who hoined the company vefore 15th of the month.
159.
Delete from emp where deprno in(select deptno from emp group by deptno having
count(*)>3);
160.
Delete those employees who hoined the company 21 years back from today.
(or)
163.
Display the department name the no of characters of which is equal to no of
employees in any other department.
Select dname from dept where length(dname) in(select count(*) from emp group by
deptno);
164.
165.
Count the no of employees who are working as manager (use set operation).
Select count(*) from emp where empno in(select mgr from emp);
166.
Display the name of then dept those employees who joined the company on the
same date.
167.
him.
Display the manager who is having maximum number of employees working under
Select mgr from emp group by mgr having count(*)=(select max(count(mgr)) from
emp group by mgr);
168.
List out employeesname and salary increased by 15% and expredded as whole
number of dollars.
169.
Produce the output of the emp table EMPLOYEE_AND_JOB for ename and job.
170.
171.
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.
Union
Union
176.
Write quary to calculate the length of employee has been with the company.
177.
Display those managers who are getting less than his employees sal.
Select empno from emp e where sal<any(select sal from emp where mgr=e.empno);
178.
Print rthe details of all the employees who are sub ordinate to blake.
Select * from emp where mgr=(select empno from emp where ename=BLAKE);
179.
180.
Display those employees whose manager name is hones and also with his manager
name.
181. Select * from emp wher mgr=(select empno from emp where ename=jones)
182.
union
Select * from emp where empno=(select mgt from emp where ename=JONES);
183.
Define variable represenring the expressions used to calculate on employees total
Annual renumaration.
Define efmp_ann_sal=(sal+nvl(comm.,0))*12;
184.
Use the variable in a statement which finds all employees who can earn 30000 a
year or more.
185.
Find out the how many manager are there with out listing them.
186.
Find out the avg sal and avg total remuneration for each job type renenber salesman
earn commission.
187.
188.
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.
Select e.ename,e.mgr,e.sal from emp e where sal in (select min(sal) from emp where
mgr=e.mgr) and e.sal>1000 order by sal;
189.
List ename ,job ,annual sal,deptno,dname and grade who earn 30000 per year and
who are not clerk.
192.
Find out the all employees who hoined the company before their manager .
Select * from emp e where hiredate <(select hiredate from emp where
empno=e.mgr);
193.
List out the all employees by name and number along with their managerd name and
number also display no manager who has no manager.
Union
196.
Find out the employees who earned the highest sal in each job typed sort in
descending sal order.
Select * from emp e where sal=(select max(sal) from emp where job=e.job);
197.
Find out the employees who earned the min sal for their job in ascending order.
Select * from emp e where sal=(select min(sal) from emp where job=e.job) order by
sal;
198.
Find out the most recently hired employees in each dept order by hiredate.
199.
Display ename,sal and deptno for each employee who earn a sal greater than the
avg of their department order by deptno.
Select ename,sal,deptno from emp e where sal>(select avg(sal) from emp where
deptno=e.deptno) orser by deptno;
200.
Select deptno,dname from dept where deptno not in(select distinct (deptno) from
emp);
201.
202.
In which year did most people join the company . display the year and number of
employees.
203.
204.
Write a quary of display against the row of the most recentlu hired emplouee. Display
ename hire date and column max date showing.
205.
Display employee who can earn more than lowest sal in dept no 30.
Select * from emp where sal>(select min(sal) from emp where deptno=30);
206.
Find employees who can earn more than every employees in deptno 30.
Sleect * from emp where sal>(select max(sal) from emp where deptno=30);
207.
Find out avg sal and avg total remainders for each job type.
208.
209.
Display the half of the enames in upper cade and remaining lower cade .
Selectconcat(upper(substr(ename,0,length(ename)/2)),
lower(substr(ename,lengtah(ename)/2+1,length(ename))))from emp;
210.
211.
Select distinct(ename) from emp e where ename in (select ename from emp where
e.empno<>empno);
212.
213.
Select empno,ename from emp e,salgrade s where e.sal between s.losal and s.hisal
and to_char(hiredate,mm)=grade;
214.
215.
216.
217.
218.
219.
220.
221.
222.
I want to give a validation saying that sal cannot be greater 10,000(note give a name
to this column)
223.
for the time being I have decided that I will not impose this validation. My boss has
agreed to pay more than 10,000
224.
my boss has changed his mind. Now he doesnt want to pay more than 10,000. so
revoke that salary constraint
225.
226.
oh! This column should be related to empno. Give a command to add this constraint
227.
228.
229.
Create table called as new emp, Using single command create this table As well as
to get data into this table (use create table as)
230.
Create table called as new emp. This table should contain only
Empno,ename,dname.
231.
Delete the rows of employees who are working in the company for more Than two
years.
232.
233.
If any employee has commission, his commission should be incremented by 10% of
his salary.
234.
235.
Display employee number,name and location of the department in which he is
working.
236.
Display ename,dname even if there no employees working in a particular
department(use outer join).
237.
238.
Display the department name along with total salary in each department.
239.
Display the department name and total number of employees in each department.
240.