SQL Queries
SQL Queries
SQL Queries
25) Display all rows from EMP table. The system should wait after
every Screen full of information.
a) Set pause on
count(*)>3;
49)Display the various jobs along with total salary for each of the
jobs where total salary is greater than 40000.
a)select job,sum(sal) from emp group by job having sum(sal)>40000;
36)Display the names of the employee in order of salary i.e the name
of
the employee earning lowest salary should salary appear first.
a)select ename from emp order by sal;
53)Display the names of salesman who earns a salary more than the
highest salary of any clerk.
a)select ename,sal from emp where job='SALESMAN' and
sal>(select
max(sal) from emp where job='CLERK');
54)Display the names of clerks who earn a salary more than the
lowest
salary of any salesman.
A)select ename from emp where job='CLERK' and sal>(select
min(sal) from
emp where job='SALESMAN');
55)Display the names of employees who earn a salary more than that
of
Jones or that of salary grether than that of scott.
a)select ename,sal from emp where sal>
(select sal from emp where ename='JONES')and sal> (select sal from
emp
where ename='SCOTT');
56)Display the names of the employees who earn highest salary in
their
respective departments.
a)select ename,sal,deptno from emp where sal in(select max(sal)
from
emp group by deptno);
57)Display the names of the employees who earn highest salaries in
their respective job groups.
a)select ename,sal,job from emp where sal in(select max(sal) from
emp
group by job)
58)Display the employee names who are working in accounting
department.
a)select ename from emp where deptno=(select deptno from dept
where
dname='ACCOUNTING')
59)Display the employee names who are working in Chicago.
a)select
empno,ename,decode(deptno,10,'ACCOUNTING',20,'RESEARCH',3
0,'SALES',40,'OPRATIONS') from emp;
60)Display the Job groups having total salary greater than the
maximum
salary for managers.
a)SELECT JOB,SUM(SAL) FROM EMP GROUP BY JOB HAVING
SUM(SAL)>(SELECT
MAX(SAL) FROM EMP WHERE JOB='MANAGER');
70)Find the First occurance of character 'a' from the following string
i.e 'Computer Maintenance Corporation'.
a)SELECT INSTR('Computer Maintenance Corporation','a',1) FROM
DUAL
85)Display the details of those who do not have any person working
under them.
a)select e.ename from emp,emp e where emp.mgr=e.empno group
by e.ename
having count(*)=1;
a)
select * from emp where deptno=(select deptno from
dept where
dname='SALES')and
sal between(select losal from salgrade where
grade=3)and
(select hisal from salgrade where grade=3);
87)Display those who are not managers and who are managers any
one.
i)display the managers names
a)select distinct(m.ename) from emp e,emp m where
m.empno=e.mgr;
ii)display the who are not managers
a)select ename from emp where ename not in(select
distinct(m.ename)
from emp e,emp m where m.empno=e.mgr);
88)Display those employee whose name contains not less than 4
characters.
a)select ename from emp where length(ename)>4;
89)Display those department whose name start with "S" while the
location name ends with "K".
a)select dname from dept where dname like 'S%' and loc like '%K';
90)Display those employees whose manager name is JONES.
a)select p.ename from emp e,emp p where e.empno=p.mgr and
e.ename='JONES';
91)Display those employees whose salary is more than 3000 after
giving
20% increment.
a)select ename,sal from emp where (sal+sal*.2)>3000;
92)Display all employees while their dept names;
s)select ename,dname from emp,dept where
emp.deptno=dept.deptno
93)Display ename who are working in sales dept.
a)select ename from emp where deptno=(select deptno from dept
where
dname='SALES');
94)Display employee name,deptname,salary and comm for those sal
in
between 2000 to 5000 while location is chicago.
a)select ename,dname,sal,comm from emp,dept where sal between
2000 and
5000 and loc='CHICAGO' and emp.deptno=dept.deptno;
95)Display those employees whose salary greter than his manager
salary.
a)select p.ename from emp e,emp p where e.empno=p.mgr and
p.sal>e.sal
96)Display those employees who are working in the same dept where
his
manager is work.
a)select p.ename from emp e,emp p where e.empno=p.mgr and
p.deptno=e.deptno;
97)Display those employees who are not working under any
manager.
a)select ename from emp where mgr is null
98)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.
a)select ename,grade from emp,salgrade where sal between losal
and hisal and deptno in(10,30) and grade<>4 and hiredate<'31-DEC82';
121)delete those records from emp table whose deptno not available
in dept table.
a)
122)Display those enames whose salary is out of the grade available
in salgrade table.
a)
123)Display employee name,sal,comm and whose net pay is greater
than
any other in the company?
a)
124)Display name of those employee who are going to retrie 31DEC-99.
if the maximum job period is 30 years?
a)
125)Display those employee whose salary is ODD value?
a)select * from emp where sal<0;
126)Display those employee whose salary contains alleast 3 digits?
a)select * from emp where length(sal)>=3;
127)Display those employee who joined in the company in the month
of
Dec?
a)select ename from emp where to_char(hiredate,'MON')='DEC';
128)Display those employees whose name contains "A"?
a)select ename from emp where instr(ename,'A')>0;
or
select ename from emp where ename like('%A%');
129)Display those employee whose deptno is available in salary?
a)select emp.ename from emp, emp e where emp.sal=e.deptno;
130)Display those employee whose first 2 characters from hiredate
-last
2 characters of salary?
a)select ename,SUBSTR(hiredate,1,2)||ENAME||substr(sal,-2,2) from
emp
131)Display those employee whose 10% of salary is equal to the year
of
joining?
a)select ename from emp where to_char(hiredate,'YY')=sal*0.1;
132)Display those employee who are working in sales or research?
a)SELECT ENAME FROM EMP WHERE DEPTNO IN(SELECT
DEPTNO FROM DEPT WHERE
DNAME IN('SALES','RESEARCH'));
133)Display the grade of jones?
a)SELECT ENAME,GRADE FROM EMP,SALGRADE WHERE SAL
BETWEEN LOSAL AND
HISAL AND Ename='JONES';
134)Display those employees who joined the company before 15 of
the
month?
a)select ename from emp where to_char(hiredate,'DD')<15;
135)Display those employee who has joined before 15th of the
month.
a)select ename from emp where to_char(hiredate,'DD')<15;
151)Give a string of the format 'nn/nn' Verify that the first and last
2 characters are numbers.And that the middle character is '/' Print the
exprection 'Yes' if valid 'No' of not valid Use the following values to
test your soluction '$12/54(Not clear).
a)
152)Employee 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 scort those whose salary contains first digits of their deptno?
a)
select ename,hiredate,last_day(next_day(hiredate,'FRIDAY')),deptno,
(
case when to_char(hiredate,'DD')<=15 then
last_day(next_day(hiredate,'FRIDAY'))
when to_char(hiredate,'DD')>15 then
last_day(next_day(add_months(hiredate,1),'FRIDAY'))
end
)from emp order by substr(sal,0,2) ;
153)Display those manager who are getting less than his employee
salary?
a)
154)Print the details of all the employees who are Sub-ordinate to
BLAKE?
a)select emp.ename from emp, emp e where emp.mgr=e.empno and
e.ename='BLAKE';
155)Display those who are working as manager using CO-relate subquery?
a)
156)Display those employee whose manager name is jones and also
with his manager name?
a)
157)Define variable representing the expression used to calculate on
employee total Annual Remunatation?
a)
158)Use the variable in a statement which finds all employees who
can earn $30,000 a year or more?
a)
159)Find out how many managers are there with out listing them?
a)
160)Find out the average salary and average total remuneration for
each job type remember sales man earn commission?
a)
161)Check whether all employees number are indeed unique?
a)
162)List out the lowest paid employees working for each manager
exclude any groups where minimum salary is less than Rs.1000 Sort
the output by salary?
a)
163)List ename,job,annual sal,deptno,dname and grade who earn
$36,000 a year or who are not Clerks?
a)
164)Find out the job that was failedin the first half of 1983 and same
job that was failed during the same period on 1984?
a)
165)Find out the employees who joined the company before their
manager?
a)
166)List out all the employees by name and number along with their
manager's name and number also display %NG who has no
manager?
a)
167)Find out the employee who earned the highest salary in each job
type Sort in desending salary order?
a)
168)Find out the employees who earned the minimum salary for their
job in Assending order?
a)
169)Find out the most resently hired employees in each department
Order by hiredate?
a)
170)Display ename,salary and deptno for each employee who earn a
salary greater than the average for then department order by
deptno?
a)
171)Display the department where there are no employees?
a)
172)Display the department no with highest annual remunaration bill
as compensation?
a)
173)In which year did most people join the company Display the year
and number of employees?
a)
174)Display the average salary figure for the department?
a)select avg(SAL) from emp group by deptno
175)Write a query of display against the row of the most recently
hired employees Display ename Hiredate and column max date
showing;
a)
176)Display employee who can earn more than lowest salary in
department no 30?
a)
177)Find employees who can earn more than every employee in
deptno?
a)
178)Select dept name deptno and sum of salary?
a)
179)Find out average salary and average total remainders for each
job type?
a)
191.
Select ename if ename exists more than once.
a)
select ename from emp e group by ename having
count(*)>1;
192.
a)
193.
Display those employee whose joining of month and
grade is equal.
A)
SELECT ENAME FROM EMP WHERE SAL
BETWEEN(SELECT LOSAL FROM SALGRADE
WHERE GRADE=TO_CHAR(HIREDATE,'MM')) AND
(SELECT HISAL FROM SALGRADE WHERE
GRADE=TO_CHAR(HIREDATE,'MM'));
194.
Display those employee whose joining DATE is available
in deptno.
A)
SELECT ENAME FROM EMP WHERE
TO_CHAR(HIREDATE,'DD')=DEPTNO
195.
A)
196.
emp;
A)
197.
inserting.
A)
198.
A)
199.
a)
200.
now.
a)
207.
Oh! This column should be related to empno. Give a
command to add
this constraint.
A)
ALTER TABLE EMP ADD CONSTRAINT MGR_DEPT
FOREIGN KEY(MGR) REFERENCES
EMP(EMPNO)
208.
a)
209.
This deptno column should be related to deptno column
of dept
table;
a)
alter table emp add constraint dept_001 foreign
key(deptno)
reference dept(deptno)
[deptno should be primary key]
201.
Now increase the length of ename column to 30
characters.
a)
alter table emp modify(ename varchar2(30));
202.
206.
a)
203.
I want to give a validation saying that salary cannot be
greater
10,000(note give a name to this constraint)
a)
alter table emp add constraint chk_001
check(sal<=10000)
204.
For the time being I have decided that I will not impose
this
validation.
My boss has agreed to pay more than 10,000.
a)
again alter the table or drop constraint with
alter table emp drop constraint chk_001
(or)Disable the constraint by
using
alter table emp modify constraint chk_001
disable;
205.
My boss has changed his mind. Now he doesn't want to
pay more
than 10,000.
so revoke that salary constraint.
a)
alter table emp modify constraint chk_001 enable;
210.
Give the command to add the constraint.
A)
alter table <table_name) add constraint
<constraint_name>
<constraint type>
211.
Create table called as newemp. Using single command
create this
table as well as get data into this table(use create table as);
a)
create table newemp as select * from emp;
212.
Create table called as newemp. This table should
contain only
empno,ename,dname.
a)
create table newemp as select empno,ename,dname
from emp,dept where
1=2;
213.
Delete the rows of employees who are working in the
company for
more than 2 years.
a)
delete from emp where (sysdate-hiredate)/365>2;
214.
Provide a commission(10% Comm Of Sal) to employees
who are not
earning any commission.
a)
select sal*0.1 from emp where comm is null
215.
If any employee has commission his commission should
be
incremented by 10% of his salary.
a)
update emp set comm=sal*.1 where comm is not null;
216.
Display employee name and department name for each
employee.
a)
select empno,dname from emp,dept where
emp.deptno=dept.deptno
217.
Display employee number,name and location of the
department in which he is working.
a)
select empno,ename,loc,dname from emp,dept where
emp.deptno=dept.deptno;
218.
Display ename,dname even if there are no employees
working in a particular department(use outer join).
a)
select ename,dname from emp,dept where
emp.deptno=dept.deptno(+)
219.
Display employee name and his manager name.
a)
select p.ename,e.ename from emp e,emp p where
e.empno=p.mgr;
220.
Display the department name and total number of
employees in each
department.
a)
select dname,count(ename) from emp,dept where
emp.deptno=dept.deptno
group by dname;
221.
Display the department name along with total salary in
each
department.
a)
select dname,sum(sal) from emp,dept where
emp.deptno=dept.deptno
group by dname;
222.
Display itemname and total sales amount for each item.
a)
select itemname,sum(amount) from item group by
itemname;
223.
25)Display the average difference between Scost and Dcost for each
lnaguage.
a)select avg(scost-dcost) from software;
38)Display the names of those who have done the DAP course.
a)select pname from studies where course='DAP';
82)In which year were the most number of programmers were born.
a)
a)
84)Who are the male programmers earning below the average salary
of the female programmers.
a)select pname from programer where sex='M' and salary<(select
avg(salary) from programer where sex='F')
85)Who are the female programmers earning more than the highest
paid male programmers.
a)select pname from programer where sex='F' and salary>(select
max(salary) from programer where sex='F')
86)which language has been stated as profile by most of the
programmers.
a)
87)Display the details of those who are drawing the same salary.
a)
88)Display the details of the software developed by the male
programmers earning more than 3000.
a)
89)Display the details of the packages developed in pascal by female
programmers.
a)
90)Display the details of the programmers who joined before 1990.
a)
91)Display the details of the software develoed in c by female
programmers of pragathi.
a)
92)Display the number of packages, number of copies sold and sales
value of each programmer institute wise.
a)
93)Display the details of the software developed in Dbase by male
programmers who belong to the institute in which most number of
programmers studied.
a)
94)Display the details of software developed by the male
programmers born after 1965 and female programmers born before
1975.
a)
112)List each prof with the number of programmers having that prof
and the number of packages developed in that prof.
a)