You are on page 1of 15

SQL Queries

1)Display the details of all employees a)select ename from emp where hiredate < '30-
a)select * from emp; JUN-1990' or hiredate >
'31-DEC-90';
2)Display the depart informaction from
department table 14)Display current Date.
a)select * from dept; a)select sysdate from dual;

3)Display the name and job for all the employees 15)Display the list of all users in your
a)select ename,job from emp; database(use catalog table).
a)select username from all_users;
4)Display the name and salary for all the
employees 16)Display the names of all tables from current
a)select ename,sal from emp; user;
a)select tname from tab;
5)Display the employee no and totalsalary for all
the employees 17)Display the name of the current user.
a)select empno,sal+comm as total from emp a)show user
group by empno;
18)Display the names of employees working in
6)Display the employee name and annual salary depart number 10 or 20 or
for all employees. 40 or employees working as CLERKS, SALESMAN
a)select ename,sal * 12 as annualsalary from or ANALYST.
emp; a) Select ename from emp where deptno
in(10,20,40) or job
7)Display the names of all the employees who are in('CLERKS','SALESMAN','ANALYST');
working in depart
number 10. 19) Display the names of employees whose name
a)select emame from emp where deptno=10; starts with alphabet S.
a)select ename from emp where ename like 'S%';
8)Display the names of all the employees who are
working as clerks and 20) Display the Employee names for employees
drawing a salary more than 3000. whose name ends with Alphabet S.
a)select ename from emp where job='CLERKS' a) Select ename from emp where ename like
and sal>3000; '%S';

9)Display the employee number and name who 21) Display the names of employees whose
are earning comm. names have second alphabet A in their names.
a)select empno,ename from emp where comm is a) Select ename from EMP where ename like '_A
not null; %';

10)Display the employee number and name who 22) select the names of the employee whose
do not earn any comm. names is exactly five
a)select empno,ename from emp where comm is Characters in length.
null; a) select ename from emp where
length(ename)=5;
11)display the names of employees who are
working as clerks,salesman or 23) Display the names of the employee who are
analyst and drawing a salary more than 3000. not working as MANAGERS.
A)select ename from emp where job='CLERK' OR a) Select ename from emp where job not in
JOB='SALESMAN' OR ('MANAGER');
JOB='ANALYST' AND SAL>3000;
24)Display the names of the employee who are
12)display the names of the employees who are not working as SALESMAN OR CLERK OR
working in the company ANALYST.
for the past 5 years; A)select ename from emp where job not
a)select ename from emp where in('SALESMAN','CLERK','ANALYST');
to_char(sysdate,'YYYY')-
to_char(hiredate,'YYYY')>=5; 25) Display all rows from EMP table. The system
should wait after every Screen full of information.
13)Display the list of employcees who have joined a) Set pause on
the company before
30-JUN-90 or after 31-DEC-90.
26) Display the total number of employee working 12).The name
in the company. of the employee earning highest annual salary
a) Select count (*) from EMP; should apper first.
a)select ename,sal*12 from emp order by sal
27) Display the total salary beiging paid to all desc;
employees.
41)Display name,salary,hra,pf,da,total salary for
a)select sum(sal) from emp; each employee. The
output should be in
28)Display the maximum salary from emp table. the order of total salary,hra 15% of salary,da 10%
a)select max(sal) from emp; of salary,pf 5%
salary,total salary will be(salary+hra+da)-pf.
29)Display the minimum salary from emp table.
a)select min(sal) from emp; a)select ename,sal,sal/100*15 as hra,sal/100*5 as
pf,sal/100*10 as
30)Display the average salary from emp table. da,sal+sal/100*15+sal/100*10-sal/100*5 as total
a)select avg(sal) from emp; from emp;

31)Display the maximum salary being paid to 42)Display depart numbers and total number of
CLERK. employees working in each
a)select max(sal) from emp where job='CLERK'; department.
a)select deptno,count(deptno)from emp group by
32)Display the maximum salary being paid to deptno;
depart number 20.
a)select max(sal) from emp where deptno=20; 43)Display the various jobs and total number of
employees within each
33)Display the minimum salary being paid to any job group.
SALESMAN. a)select job,count(job)from emp group by job;
a)select min(sal) from emp where
job='SALESMAN'; 44)Display the depart numbers and total salary
for each department.
34)Display the average salary drawn by a)select deptno,sum(sal) from emp group by
MANAGERS. deptno;
a)select avg(sal) from emp where
job='MANAGER'; 45)Display the depart numbers and max salary
for each department.
35)Display the total salary drawn by ANALYST a)select deptno,max(sal) from emp group by
working in depart number deptno;
40.
a)select sum(sal) from emp where job='ANALYST' 46)Display the various jobs and total salary for
and deptno=40; each job
a)select job,sum(sal) from emp group by job;
36)Display the names of the employee in order of
salary i.e the name of 47)Display the various jobs and total salary for
the employee earning lowest salary should salary each job
appear first. a)select job,min(sal) from emp group by job;
a)select ename from emp order by sal;
48)Display the depart numbers with more than
37)Display the names of the employee in three employees in each
descending order of salary. dept.
a)select ename from emp order by sal desc; a)select deptno,count(deptno) from emp group by
deptno having
38)Display the names of the employee in order of count(*)>3;
employee name.
a)select ename from emp order by ename; 49)Display the various jobs along with total salary
for each of the
39)Display empno,ename,deptno,sal sort the jobs where total salary is greater than 40000.
output first base on name a)select job,sum(sal) from emp group by job
and within name by deptno and with in deptno by having sum(sal)>40000;
sal.
a) select empno,ename,deptno,sal from emp 50)Display the various jobs along with total
order by ename,deptno,sal number of employees in
each job.The output should contain only those
40)Display the name of the employee along with jobs with more than three
their annual salary(sal* employees.
a)select job,count(empno) from emp group by job salary for managers.
having count(job)>3 a)SELECT JOB,SUM(SAL) FROM EMP GROUP BY JOB
HAVING SUM(SAL)>(SELECT
51)Display the name of the empployee who earns MAX(SAL) FROM EMP WHERE JOB='MANAGER');
highest salary.
a)select ename from emp where sal=(select 61)Display the names of employees from
max(sal) from emp); department number 10 with salary
grether than that of any employee working in
52)Display the employee number and name for other department.
employee working as clerk a)select ename from emp where deptno=10 and
and earning highest salary among clerks. sal>any(select sal from emp
a)select empno,ename from emp where where where deptno not in 10).
job='CLERK' and sal=(select
max(sal) from emp where job='CLERK'); 62)Display the names of the employees from
department number 10 with
53)Display the names of salesman who earns a salary greater than that of all employee working
salary more than the in other departments.
highest salary of any clerk. a)select ename from emp where deptno=10 and
a)select ename,sal from emp where sal>all(select sal from emp
job='SALESMAN' and sal>(select where deptno not in 10).
max(sal) from emp where job='CLERK');
63)Display the names of the employees in
54)Display the names of clerks who earn a salary Uppercase.
more than the lowest a)select upper(ename)from emp
salary of any salesman.
A)select ename from emp where job='CLERK' and 64)Display the names of the employees in
sal>(select min(sal) from Lowecase.
emp where job='SALESMAN'); a)select lower(ename)from emp

55)Display the names of employees who earn a 65)Display the names of the employees in
salary more than that of Propercase.
Jones or that of salary grether than that of scott. a)select initcap(ename)from emp;
a)select ename,sal from emp where sal>
(select sal from emp where ename='JONES')and 66)Display the length of Your name using
sal> (select sal from emp appropriate function.
where ename='SCOTT'); a)select length('name') from dual

56)Display the names of the employees who earn 67)Display the length of all the employee names.
highest salary in their a)select length(ename) from emp;
respective departments.
a)select ename,sal,deptno from emp where sal 68)select name of the employee concatenate with
in(select max(sal) from employee number.
emp group by deptno); select ename||empno from emp;

57)Display the names of the employees who earn 69)User approprate function and extract 3
highest salaries in characters starting from 2
their respective job groups. characters from the following string 'Oracle'. i.e
a)select ename,sal,job from emp where sal the out put should be
in(select max(sal) from emp 'ac'.
group by job) a)select substr('oracle',3,2) from dual

58)Display the employee names who are working 70)Find the First occurance of character 'a' from
in accounting department. the following string
a)select ename from emp where deptno=(select i.e 'Computer Maintenance Corporation'.
deptno from dept where a)SELECT INSTR('Computer Maintenance
dname='ACCOUNTING') Corporation','a',1) FROM DUAL

59)Display the employee names who are working 71)Replace every occurance of alphabhet A with
in Chicago. B in the string
a)select ename from emp where deptno=(select Allens(use translate function)
deptno from dept where a)select translate('Allens','A','B') from dual
LOC='CHICAGO')
72)Display the informaction from emp
60)Display the Job groups having total salary table.Where job manager is found
greater than the maximum
it should be displayed as boos(Use replace 84)Display the jobs which are unique to
function). department 10.
a)select replace(JOB,'MANAGER','BOSS') FROM a)select distinct(job) from emp where deptno=10
EMP;
85)Display the details of those who do not have
73)Display empno,ename,deptno from emp any person working
table.Instead of display under them.
department numbers display the related a)select e.ename from emp,emp e where
department name(Use decode function). emp.mgr=e.empno group by e.ename
a)select having count(*)=1;
empno,ename,decode(deptno,10,'ACCOUNTING',2
0,'RESEARCH',30,'SALES',40,'OPRATIONS') from 86)Display the details of those employees who
emp; are in sales department
and grade is 3.
74)Display your age in days.
a)select to_date(sysdate)-to_date('10-sep- a) select * from emp where deptno=(select
77')from dual deptno from dept where
dname='SALES')and
75)Display your age in months. sal between(select losal from salgrade
a)select months_between(sysdate,'10-sep-77') where grade=3)and
from dual (select hisal from salgrade where
grade=3);
76)Display the current date as 15th Augest Friday
Nineteen Ninety 87)Display those who are not managers and who
Saven. are managers any one.
a)select to_char(sysdate,'ddth Month day year') i)display the managers names
from dual a)select distinct(m.ename) from emp e,emp m
where m.empno=e.mgr;
77)Display the following output for each row from ii)display the who are not managers
emp table. a)select ename from emp where ename not
in(select distinct(m.ename)
from emp e,emp m where m.empno=e.mgr);
78)scott has joined the company on wednesday
13th August ninten nintey. 88)Display those employee whose name contains
a)select ENAME||' HAS JOINED THE COMPANY ON not less than 4
'||to_char(HIREDATE,'day characters.
ddth Month year') from EMP; a)select ename from emp where
length(ename)>4;
79)Find the date for nearest saturday after
current date. 89)Display those department whose name start
a)SELECT NEXT_DAY(SYSDATE,'SATURDAY')FROM with "S" while the
DUAL; location name ends with "K".
a)select dname from dept where dname like 'S%'
80)display current time. and loc like '%K';
a)select to_char(sysdate,'hh:MM:ss') from dual.
90)Display those employees whose manager
81)Display the date three months Before the name is JONES.
current date. a)select p.ename from emp e,emp p where
a)select add_months(sysdate,3) from dual; e.empno=p.mgr and
e.ename='JONES';
82)Display the common jobs from department
number 10 and 20. 91)Display those employees whose salary is more
a)select job from emp where deptno=10 and job than 3000 after giving
in(select job from emp 20% increment.
where deptno=20); a)select ename,sal from emp where
(sal+sal*.2)>3000;
83)Display the jobs found in department 10 and
20 Eliminate duplicate 92)Display all employees while their dept names;
jobs. s)select ename,dname from emp,dept where
a)select distinct(job) from emp where deptno=10 emp.deptno=dept.deptno
or deptno=20
or 93)Display ename who are working in sales dept.
select distinct(job) from emp where deptno a)select ename from emp where deptno=(select
in(10,20); deptno from dept where
dname='SALES');
a)select ename,sal,grade from emp,salgrade
94)Display employee name,deptname,salary and where sal between losal and
comm for those sal in hisal
between 2000 to 5000 while location is chicago. and ename ='FORD' AND HISAL=SAL;
a)select ename,dname,sal,comm from emp,dept
where sal between 2000 and 104)Display employee name,job,depart name
5000 and loc='CHICAGO' and ,manager name,his grade and
emp.deptno=dept.deptno; make out an under department wise?
a)SELECT
95)Display those employees whose salary greter E.ENAME,E.JOB,DNAME,EMP.ENAME,GRADE FROM
than his manager salary. EMP,EMP
a)select p.ename from emp e,emp p where E,SALGRADE,DEPT
e.empno=p.mgr and p.sal>e.sal WHERE EMP.SAL BETWEEN LOSAL AND HISAL
AND EMP.EMPNO=E.MGR AND
96)Display those employees who are working in EMP.DEPTNO=DEPT.DEPTNO ORDER BY DNAME
the same dept where his
manager is work. 105)List out all employees name,job,salary,grade
a)select p.ename from emp e,emp p where and depart name for every one in the company
e.empno=p.mgr and except 'CLERK'.Sort on salary display the highest
p.deptno=e.deptno; salary?
a)SELECT ENAME,JOB,DNAME,SAL,GRADE FROM
97)Display those employees who are not working EMP,SALGRADE,DEPT WHERE
under any manager. SAL BETWEEN LOSAL AND HISAL AND
a)select ename from emp where mgr is null EMP.DEPTNO=DEPT.DEPTNO AND JOB NOT
IN('CLERK')ORDER BY SAL ASC;
98)Display grade and employees name for the
dept no 10 or 30 but grade 106)Display the employee name,job and his
is not 4 while joined the company before 31-dec- manager.Display also employee who are without
82. manager?
a)select ename,grade from emp,salgrade where a)select e.ename,e.job,eMP.ename AS Manager
sal between losal and hisal and deptno in(10,30) from emp,emp e where emp.empno(+)=e.mgr
and grade<>4 and hiredate<'31-DEC-82';
107)Find out the top 5 earners of company?
a)SELECT DISTINCT SAL FROM EMP E WHERE
99)Update the salary of each employee by 10% 5>=(SELECT COUNT(DISTINCT SAL)
increment who are not eligiblw for commission. FROM EMP A WHERE A.SAL>=E.SAL)ORDER BY
a)update emp set sal=sal+sal*10/100 where SAL DESC;
comm is null;

100)SELECT those employee who joined the 108)Display name of those employee who are
company before 31-dec-82 while their dept getting the highest salary?
location is newyork or Chicago. a)select ename from emp where sal=(select
a)SELECT EMPNO,ENAME,HIREDATE,DNAME,LOC max(sal) from emp);
FROM EMP,DEPT WHERE
(EMP.DEPTNO=DEPT.DEPTNO)AND 109)Display those employee whose salary is
HIREDATE <'31-DEC-82' AND DEPT.LOC equal to average of maximum
IN('CHICAGO','NEW YORK'); and minimum?
a)select ename from emp where sal=(select
101)DISPLAY EMPLOYEE max(sal)+min(sal)/2 from
NAME,JOB,DEPARTMENT,LOCATION FOR ALL WHO emp);
ARE
WORKING AS MANAGER? 110)Select count of employee in each department
A)select ename,JOB,DNAME,LOCATION from where count greater than 3?
emp,DEPT where mgr is not null; a)select count(*) from emp group by deptno
having count(deptno)>3
102)dISPLAY THOSE EMPLOYEES WHOSE
MANAGER NAME IS JONES? --[AND ALSO 111)Display dname where at least 3 are working
DISPLAY THEIR MANAGER NAME]? and display only
A) SELECT P.ENAME FROM EMP E, EMP P WHERE department name?
E.EMPNO=P.MGR AND a)select distinct d.dname from dept d,emp e
E.ENAME='JONES'; where d.deptno=e.deptno and
3>any (select count(deptno) from emp group by
103)Display name and salary of ford if his salary deptno)
is equal to hisal of
his grade
112)Display name of those managers name 123)Display employee name,sal,comm and whose
whose salary is more than average salary of his net pay is greater than
company? any other in the company?
a)SELECT E.ENAME,EMP.ENAME FROM EMP,EMP E a)
WHERE EMP.EMPNO=E.MGR AND
E.SAL>(SELECT AVG(SAL) FROM EMP); 124)Display name of those employee who are
going to retrie 31-DEC-99.
113)Display those managers name whose salary if the maximum job period is 30 years?
is more than average salary of his employee? a)
a)SELECT DISTINCT EMP.ENAME FROM EMP,EMP E
WHERE E.SAL <(SELECT AVG(EMP.SAL) FROM 125)Display those employee whose salary is ODD
EMP value?
WHERE EMP.EMPNO=E.MGR GROUP BY a)select * from emp where sal<0;
EMP.ENAME) AND EMP.EMPNO=E.MGR;
126)Display those employee whose salary
114)Display employee name,sal,comm and net contains alleast 3 digits?
pay for those employee whose net pay is greter a)select * from emp where length(sal)>=3;
than or equal to any other employee salary of
the company? 127)Display those employee who joined in the
a)select ename,sal,comm,sal+nvl(comm,0) as company in the month of
NetPay from emp where sal+nvl(comm,0) >any Dec?
(select sal from emp) a)select ename from emp where
to_char(hiredate,'MON')='DEC';
115)Display those employees whose salary is less
than his manager but more than salary of any 128)Display those employees whose name
other manager? contains "A"?
a) a)select ename from emp where
instr(ename,'A')>0;
116)Display all employees names with total sal of or
company with each select ename from emp where ename like('%A
employee name? %');
a)SELECT ENAME,(SELECT SUM(SAL) FROM EMP)
FROM EMP; 129)Display those employee whose deptno is
available in salary?
117)Find out last 5(least)earners of the a)select emp.ename from emp, emp e where
company.? emp.sal=e.deptno;
a)SELECT DISTINCT SAL FROM EMP E WHERE
5>=(SELECT COUNT(DISTINCT SAL) 130)Display those employee whose first 2
FROM EMP A WHERE A.SAL<=E.SAL)ORDER BY characters from hiredate -last
SAL DESC; 2 characters of salary?
a)select ename,SUBSTR(hiredate,1,2)||ENAME||
118)Find out the number of employees whose substr(sal,-2,2) from emp
salary is greater than their manager salary?
a)SELECT E.ENAME FROM EMP ,EMP E WHERE 131)Display those employee whose 10% of salary
EMP.EMPNO=E.MGR AND is equal to the year of
EMP.SAL<E.SAL; joining?
a)select ename from emp where
119)Display those manager who are not working to_char(hiredate,'YY')=sal*0.1;
under president but they are working under any
other manager? 132)Display those employee who are working in
a) sales or research?
a)SELECT ENAME FROM EMP WHERE DEPTNO
120)Display those department where no IN(SELECT DEPTNO FROM DEPT WHERE
employee working? DNAME IN('SALES','RESEARCH'));
a)select dname from emp,dept where
emp.deptno not in(emp.deptno) 133)Display the grade of jones?
a)SELECT ENAME,GRADE FROM EMP,SALGRADE
121)delete those records from emp table whose WHERE SAL BETWEEN LOSAL AND
deptno not available in dept table. HISAL AND Ename='JONES';
a)
134)Display those employees who joined the
122)Display those enames whose salary is out of company before 15 of the
the grade available in salgrade table. month?
a) a)select ename from emp where
to_char(hiredate,'DD')<15;
a)
135)Display those employee who has joined
before 15th of the month. 149)Print lost of employees displaying "just
a)select ename from emp where salary" if more than 1500
to_char(hiredate,'DD')<15; if exactly 1500 display 'On target' if less than
1500 Display below 1500?
136)Delete those records where no of employees A)select ename,sal,(case when sal>1500 then
in a particular 'Below_target' when
department is less than 3. sal=1500 then 'On_targer' when sal<1500 then
a)delete from emp where deptno=(select deptno 'less than target' else 'kkkkk' end )from emp
from emp
group by deptno having count(deptno)<3); 150)WHICH query to calcuate the length of time
any employee has been with the company?
137)Display the department name the no of
characters of which
is equal to no of employee in any other
department.
a) 151)Give a string of the format 'nn/nn' Verify that
the first and last
138)Display the name of the department where 2 characters are numbers.And that the middle
no employee working. character is '/' Print the
a) exprection 'Yes' if valid 'No' of not valid Use the
following values to test your soluction '$12/54(Not
139)Display those employees who are working as clear).
manager. a)
a)
152)Employee hire on 15th of any month are paid
140)Count the no of employees who are working on the last Friday of that month. Those hired after
as manager(using set 15th are paid the last Friday of the following
operations). month.Print a list of employees.their hire date
a) and first pay date scort those whose salary
contains first digits of their deptno?
141)Display the name of the dept those employee a)
who joined the company select
on the same date? ename,hiredate,last_day(next_day(hiredate,'FRID
a) AY')),deptno,
(
142)Display those employees whose grade is case when to_char(hiredate,'DD')<=15 then
equal to any number of sal last_day(next_day(hiredate,'FRIDAY'))
but not equal to first number of sal? when to_char(hiredate,'DD')>15 then
a) last_day(next_day(add_months(hiredate,1),'FRIDA
Y'))
143)Count the no of empployee working as end
manager using set operaction? )from emp order by substr(sal,0,2) ;
a)

144)display the name of the employees who


joined the same date. 153)Display those manager who are getting less
a) than his employee
salary?
145)Display the manager who is having maximum a)
number of employees working under him?
a) 154)Print the details of all the employees who are
Sub-ordinate to
146)list out employee name and salary increased BLAKE?
by 15% and expressed as whole number of a)select emp.ename from emp, emp e where
Dollars? emp.mgr=e.empno and
a) e.ename='BLAKE';

147)Produce the output of the emp table 155)Display those who are working as manager
"EMPLOYEE AND JOB" for ename and job? using CO-relate sub-query?
a) a)

148)List all employee with hiredate in the format 156)Display those employee whose manager
'june 4 1988'? name is jones and also with his manager name?
a) 170)Display ename,salary and deptno for each
employee who earn a salary greater than the
157)Define variable representing the expression average for then department order by deptno?
used to calculate on a)
employee total Annual Remunatation?
a) 171)Display the department where there are no
employees?
158)Use the variable in a statement which finds a)
all employees who can earn $30,000 a year or
more? 172)Display the department no with highest
a) annual remunaration bill as compensation?
a)
159)Find out how many managers are there with
out listing them? 173)In which year did most people join the
a) company Display the year and number of
employees?
160)Find out the average salary and average total a)
remuneration for each job type remember sales
man earn commission? 174)Display the average salary figure for the
a) department?
a)select avg(SAL) from emp group by deptno
161)Check whether all employees number are
indeed unique? 175)Write a query of display against the row of
a) the most recently hired employees Display ename
Hiredate and column max date showing;
162)List out the lowest paid employees working a)
for each manager exclude any groups where
minimum salary is less than Rs.1000 Sort the 176)Display employee who can earn more than
output by salary? lowest salary in department no 30?
a) a)

163)List ename,job,annual sal,deptno,dname and 177)Find employees who can earn more than
grade who earn $36,000 a year or who are not every employee in deptno?
Clerks? a)
a)
178)Select dept name deptno and sum of salary?
164)Find out the job that was failedin the first half a)
of 1983 and same
job that was failed during the same period on 179)Find out average salary and average total
1984? remainders for each job type?
a) a)

165)Find out the employees who joined the 180)Find all departments which have more than 3
company before their manager? employees?
a) a)

166)List out all the employees by name and 181)Check whether employees number are
number along with their unique?
manager's name and number also display %NG a)
who has no manager?
a) 182)List lowest paid employees working for each
manager exclude any
167)Find out the employee who earned the groups where the minimum salary less than 1000.
highest salary in each job Sort the output by
type Sort in desending salary order? salary?
a) a)

168)Find out the employees who earned the 183)If the pay day is next friday after 15th and
minimum salary for their job in Assending order? 30th of every
a) month.what is the next pay day from their hire
date for employee in emp table?
169)Find out the most resently hired employees a)
in each department Order by hiredate?
a)
184)If an employee is taken by you today in your WHERE GRADE=TO_CHAR(HIREDATE,'MM')) AND
organisation. (SELECT HISAL FROM SALGRADE WHERE
And it is a policy in your company to have a GRADE=TO_CHAR(HIREDATE,'MM'));
review after 9 months the
joined date (and of 1st of next month after 9 194. Display those employee whose joining
months )how many days from today your DATE is available in deptno.
employees has To wait for a review? A) SELECT ENAME FROM EMP WHERE
a) TO_CHAR(HIREDATE,'DD')=DEPTNO

185)Display employee name and his salary whose 195. Display those employees name as
salary is greater than highest average of follows
department number? A ALLEN
a)SELECT SAL FROM EMP WHERE SAL>(SELECT B BLAKE
MAX(AVG(SAL)) FROM EMP GROUP BY A) SELECT SUBSTR(ENAME,1,1),ENAME
DEPTNO); FROM EMP;

186)Display the 10th record of emp table(without 196. List out the employees
using rowid) ename,sal,PF(20% OF SAL) from emp;
a) SELECT * FROM EMP WHERE A) SELECT ENAME,SAL,SAL*.2 AS PF FROM
ROWNUM<11 EMP;
MINUS
SELECT * FROM EMP WHERE 197. Display RSPS from emp without using
ROWNUM<10 updating inserting.
A)
187)Display the half of the ename's in upper case
and remaining 198. Create table emp with only one column
lowercase? empno;
a) SELECT A) create table emp as select empno from
SUBSTR(LOWER(ENAME),1,3)|| emp where 1=2;
SUBSTR(UPPER(ENAME),3,LENGTH(ENAME)) FROM
EMP; 199. Add this column to emp table ename
vrachar2(20).
188. Display the 10th record of emp table a) alter table emp add(ename
without using group by and rowid? varchar2(20));
A) SELECT * FROM EMP WHERE
ROWNUM<11 200. Oops I forgot give the primary key
MINUS constraint. Add in now.
SELECT * FROM EMP WHERE a) alter table emp add primary
ROWNUM<10 key(empno);

189. Delete the 10th record of emp table. 201. Now increase the length of ename
A) DELETE FROM EMP WHERE column to 30 characters.
EMPNO=(SELECT EMPNO FROM EMP WHERE a) alter table emp modify(ename
ROWNUM<11 varchar2(30));
MINUS
SELECT EMPNO FROM EMP WHERE 202. Add salary column to emp table.
ROWNUM<10) alter table emp add(sal number(10));

190. Create a copy of emp table; 203. I want to give a validation saying that
a) create table new_table as select * from salary cannot be greater
emp where 1=2; 10,000(note give a name to this constraint)
a) alter table emp add constraint chk_001
191. Select ename if ename exists more than check(sal<=10000)
once.
a) select ename from emp e group by 204. For the time being I have decided that I
ename having count(*)>1; will not impose this
validation.
192. Display all enames in reverse order? My boss has agreed to pay more than
(SMITH:HTIMS). 10,000.
a) SELECT REVERSE(ENAME)FROM EMP; a) again alter the table or drop constraint
with
193. Display those employee whose joining of alter table emp drop constraint
month and grade is equal. chk_001 (or)Disable the constraint by
A) SELECT ENAME FROM EMP WHERE SAL using
BETWEEN(SELECT LOSAL FROM SALGRADE
alter table emp modify a) update emp set comm=sal*.1 where
constraint chk_001 disable; comm is not null;
205. My boss has changed his mind. Now he
doesn't want to pay more 216. Display employee name and department
than 10,000. name for each employee.
so revoke that salary constraint. a) select empno,dname from emp,dept
a) alter table emp modify constraint where emp.deptno=dept.deptno
chk_001 enable;
217. Display employee number,name and
206. Add column called as mgr to your emp location of the department in which he is working.
table; a) select empno,ename,loc,dname from
a) alter table emp add(mgr number(5)); emp,dept where
emp.deptno=dept.deptno;
207. Oh! This column should be related to
empno. Give a command to add 218. Display ename,dname even if there are
this constraint. no employees working in a particular
A) ALTER TABLE EMP ADD CONSTRAINT department(use outer join).
MGR_DEPT FOREIGN KEY(MGR) REFERENCES a) select ename,dname from emp,dept
EMP(EMPNO) where emp.deptno=dept.deptno(+)

208. Add deptno column to your emp table; 219. Display employee name and his
a) alter table emp add(deptno number(5)); manager name.
a) select p.ename,e.ename from emp
209. This deptno column should be related to e,emp p where e.empno=p.mgr;
deptno column of dept
table; 220. Display the department name and total
a) alter table emp add constraint dept_001 number of employees in each
foreign key(deptno) department.
reference dept(deptno) a) select dname,count(ename) from
[deptno should be primary key] emp,dept where emp.deptno=dept.deptno
group by dname;
210. Give the command to add the constraint.
A) alter table <table_name) add constraint 221. Display the department name along with
<constraint_name> total salary in each
<constraint type> department.
a) select dname,sum(sal) from emp,dept
211. Create table called as newemp. Using where emp.deptno=dept.deptno
single command create this group by dname;
table as well as get data into this table(use create
table as); 222. Display itemname and total sales
a) create table newemp as select * from amount for each item.
emp; a) select itemname,sum(amount) from item
group by itemname;
212. Create table called as newemp. This
table should contain only 223. Give the following commands:
empno,ename,dname. Delete from emp where job 'clerk'
a) create table newemp as select Inset into emp
empno,ename,dname from emp,dept where without giving any further commands move
1=2; to another client
system and log into the same user give the
213. Delete the rows of employees who are following command
working in the company for select * from emp.
more than 2 years. 1.Are the above changes reflected in this
a) delete from emp where (sysdate- user?(yes)
hiredate)/365>2; 2.Goto your first system, and give commit.
Come back to second
214. Provide a commission(10% Comm Of system and give the following command
Sal) to employees who are not Select * from emp.
earning any commission. Ans:Changes Will be affect in second
a) select sal*0.1 from emp where comm is system.
null Q)Write a Query To Delete The Repeted Rows
from emp table;
215. If any employee has commission his a)delete from emp where rowid not in(select
commission should be min(rowid)from emp group by
incremented by 10% of his salary. ename)
/
12)Display the total selling cost of the packages
developed in each
language.
Download File |
Plain Text Attachment [
a)
Save to my Yahoo! Briefcase ]
QUERIES BASED ON PROGRAMMER, SOFTWARE & 13)Display the cost of package developed by
STUDIES TABLES each programmer.
__________________________________________________ a)select pname,scost+dcost from software;
____
14)Display the sales value of the packages
1)Display the number of packages developed in developed by each
each. programmer.
a)select count(title) from software group by a)
dev_in;
15)Display the number of packages sold by each
2)Display the number of packages developed by programmer.
each person. a)select count(pname) from software group by
a)select count(title) from software group by pname;
pname;
16)Display the sales cost of the packages
3)Display the number of male and female developed by each programmer
programmers. languagewise.
a)select sex,count(sex) from programer group by a)
sex;
17)Display the language name with average
4)Display the costiest package and the highest development cost and selling
selling package cost.
developed in each language. a)
a)select dev_in,max(dcost),max(sold) from
software group by dev_in; 18)Display the name of each programmer with
the costiest package
5)Display the number of people born in each year. cheapest package
a)select to_char(dob,'YY'),count(dob) from developed by him/her.
programer group by a)
to_char(dob,'YY');
19)Display each institute name with number of
6)Display the number of people joined in each courses and average cost
month. per course.
a)select to_char(dob,'MM'),count(dob) from a)select inst,count(course),avg(ccost) from
programer group by studies group by inst;
to_char(dob,'MM');
20)Display each institute name with number of
7)Display the language-wise count of prof1. students.
a)select prof1,count(prof1) from programer group a)select inst,count(inst)from studies group by
by prof1; inst;

8)Display the number of people in each salary 21)Display the names of male programmers.
group. a)select pname from programer where sex='M';
a)select salary,count(salary) from programer
group by salary; 22)Display the programmers name and packages
developed by him/her.
9)Display the numeber of people in each institute. a)select pname,title from software;
a)select count(inst) from studies group by inst;

10)Display the number of people who studied in 23)Display the number of packages in each
each group. language, except c & c++.
a)select count(course) from studies group by a)select count(title) from software where dev_in
course; not in('C','Cpp')
group by dev_in;
11)Display the Total development cost of the
packages developed in each 24)Display the number of packages in each
language. language for which
a)select dev_in,sum(dcost) from software group development cost is greater than
by dev_in; 1000.
a)select count(title) from software where prof1 not in('C','Cpp','Oracle','Dbase') and prof2
dcost>1000 group by dev_in; not
in('C','Cpp','Oracle','Dbase') ;
25)Display the average difference between Scost
and Dcost for each 36)Find out the average selling cost for packages
lnaguage. developed in pascal.
a)select avg(scost-dcost) from software; a)select avg(scost * sold) from software where
dev_in='Pascal';
26)Display highest,lowest and average salaries
for those earning more 37)Display the names and ages of all the
than 2000. programmers.
a)select max(salary),min(salary),avg(salary) from a)select pname,(sysdate-dob)/365 as age from
programer where programer.
salary>2000;
38)Display the names of those who have done the
27)Display the total scost,dcost and amount to be DAP course.
recovered for each a)select pname from studies where course='DAP';
programmer
by those whose dcost has not yet been recovered. 39)Display the name and date of birth of all
a) programmers born in
january.
28)Who is the highest paid c programmer. a)select pname,dob from programer where
a)select pname,salary from programer where to_char(dob,'MON')='JAN';
salary=(select max(salary)
from programer where prof1='C' or prof2='C'); 40)Display the lowest course fee.
a)SELECT MIN(CCOST) FROM STUDIES;
29)Who is the highest paid female cobol
programmer. 41)How many programmer have done the PGDCA
a)select pname,salary from programer where course.
salary=(select max(salary) a)SELECT COUNT(COURSE) FROM STUDIES
from WHERE COURSE='PGDCA';
programer where sex='F' and prof1='Cobol' or
prof2='Cobol'); 42)How much revenue has been earned through
the sale of packages
30)Display the names of the highest paid developed.
programmer for each language a)SELECT SUM(SOLD*SCOST) FROM SOFTWARE;
prof1.
a)select pname from programer where salary 43)Display the details of the software developed
in(select max(salary) from by RAMESH.
programer group by prof1) a)SELECT * FROM SOFTWARE WHERE
PNAME='RAMESH';
31)Who is the least experienced programmer.
a)select min(doj)from programer; 44)How many programmers studied at SABHARI.
a)SELECT COUNT(COURSE) FROM STUDIES
32)Who is the most experienced programmer in WHERE INST='SABHARI';
PASCAL.
a)select max(doj)from programer where 45)Display the details oF packages whose sales
prof1='Pascal' or prof2='Pascal'; crossed the 2000 mark.
a)SELECT * FROM SOFTWARE WHERE
33)Which language is known by only one SOLD>2000;
programmer.
a) 46)Find out the number of copies, which should
be sold in order to
34)Who is the youngest programmer knowing recovered the
dbase. development cost of each packages.
a)select pname from programer where a)
dob=(select max(dob) from programer
where prof1='Dbase' or prof2='Dbase'); 47)Display the details of packages for which
development cost has been recovered.
a)
35)Which female programmer earining more than
3000 does not know c,c++,oracle or dbase. 48)What is the price of the costiest software
a)select pname from programer where sex='F' developed in Basic.
and salary>3000 and a)SELECT SCOST FROM SOFTWARE WHERE
SCOST=(SELECT MAX(SCOST) FROM
STUDIES WHERE DEV_IN='BASIC'); and prof2 not in('Clipper','Cobol','Pascal');

49)How many packages are developed in Dbase. 63)Which institute has maximum number of
a)SELECT COUNT(TITLE) FROM STUDIES WHERE students.
DEV_IN='DBASE'; a)

50)What is the average coursefee. 64)Which course has been done by the maximum
a)SELECT AVG(CCOST) FROM STUDIES; number of students.
a)
51)Display the details of programmers knowing c.
a)SELECT * FROM PROGRAMER WHERE PROF1='C' 65)Display the name of the institue and course
or prof2='C'; which has below average
course fee.
52)How many programmers know either cobol or a)select inst,course from studies where
pascal. ccost<(select avg(ccost) from
a)SELECT count(pname) FROM PROGRAMER studies);
WHERE PROF1='Cobol' or prof2='Pascals';
66)Which is the costiest course.
53)How many programmers do not know pascal & a)select course from studies where ccost=(select
c. max(ccost) from
a)SELECT count(pname) FROM PROGRAMER studies);
WHERE PROF1 not in('C','Pascal')and prof2 not
in('C','Pascal') 67)Which institute conducts the costiest course.
a)select course,inst from studies where
54)How old is the oldest male programmer. ccost=(select max(ccost) from
a)select max(sysdate-dob)/365 from programer studies)
where sex='M';
68)Which course has less than the average
55)What is the average age of female number of students.
programmers. a)
a)select avg(sysdate-dob)/365 from programer
where sex='F' 69)Display the names of the courses whose fees
are within 1000/- of the
56)Calculate the experience in years for each course.
programmer and siplay a)select course from studies where ccost<1000;
along with the names in descending order.
a)select pname,(sysdate-doj)/365 from programer 70)Which package has the highest development
order by pname desc; cost.
a)select title from software where dcost=(select
57)Who are the programmers who celebrate their max(dcost) from software);
birthdays during the current month.
a)select pname from programer where 71)Which package has lowest selling price.
to_char(dob,'mm')=to_char(sysdate,'mm'); a)select title from software where dcost=(select
min(dcost) from software)
58)How many female programmers are there.
a)select count(*) from programer where sex='F'; 72)Who developed the package that has sold the
least number of copies.
59)What are the language known by the male a)select pname from software where sold=(select
programmers. min(sold)from software);
a)select prof1,prof2 from programer where
sex='M'; 73)Which language was used to develop the
package having highest cost.
60)What is the average salary. a)select dev_in from software where
a)select avg(salary) from programer; dcost=(select max(dcost)from software);

61)How many people draw between 2000 and 74)How many copies of the packages that has the
4000. least difference
a)select count(*) from programer where salary between developemt and selling cost were sold.
between 2000 and 4000; a)

62)Display the details of those who do not know 75)Which language was used to develop the
clipper,cobol or highest number of packages.
pascal. a)
a)select * from programer where prof1 not
in('Clipper','Cobol','Pascal')
76)Which programmer has developed the highest a)
number of packages.
a) 90)Display the details of the programmers who
joined before 1990.
77)Who is the author of costliest package. a)
a)select pname from software where
dcost=(select min(dcost) from software); 91)Display the details of the software develoed in
c by female programmers of pragathi.
78)Display the names of the packages which is a)
sold less than the average.
a)select title from software where sold<(select 92)Display the number of packages, number of
avg(sold) from software); copies sold and sales value of each programmer
institute wise.
79)Who are the authors of the packages which a)
have recovered more than double the
development cost. 93)Display the details of the software developed
a) in Dbase by male programmers who belong to
the institute in which most number of
80)Who is the youngest male programmer born in programmers studied.
1965. a)
a)select pname from programer where
dob=(select max(dob) from programer where 94)Display the details of software developed by
sex='M' and to_char(dob,'YYYY')=1965); the male programmers born after 1965 and
female programmers born before 1975.
81)Who is the oldest female programmer who a)
joined in 1992.
a)select pname from programer where 95)Display the details of the software that was
dob=(select max(dob) from programer where developed in the language which is neither the
sex='F' and to_char(doj,'YYYY')=1992); first nor the second proficiency of the
programmers.
82)In which year were the most number of a)
programmers were born.
a) 96)Display the name of the programmers who
have not developed any package.
83)In which language are most of the a)
programmers proficient.
a) 97)What is the total cost of the software
developed by programmer by apple.
84)Who are the male programmers earning below a)
the average salary of the female programmers.
a)select pname from programer where sex='M' 98)Who are the programmer who joined in the
and salary<(select avg(salary) from programer same day.
where sex='F') a)

85)Who are the female programmers earning 99)Who are the programmer who have the same
more than the highest paid male programmers. Prof.2.
a)select pname from programer where sex='F' a)
and salary>(select max(salary) from programer
where sex='F') 100)Display the total sales value of software,
institute wise.
86)which language has been stated as profile by a)
most of the programmers.
a) 101)In which institute is the person who
developed the costilest package.
87)Display the details of those who are drawing a)
the same salary.
a) 102)Which language listed in prof1 and prof2 has
not been used to develop any package.
88)Display the details of the software developed a)
by the male programmers earning more than
3000. 103)How much does the person who developed
a) the highest selling package earn and what course
did he/she undergo.
89)Display the details of the packages developed a)
in pascal by female programmers.
104)How many months will it take for each a)
programmer to recover the cost of the course
he/she underwent. 119)How many different courses are mentioned in
a) the studies table.
a)
105)Which is the constiest package developed by
a person with udnder 5 years Experience. 120)Display the names of the programmers
a) whose names contain 2
concurrence of the.
106)What is the average salary for those whose a)
softwares sales value is more than 50000.
a) 121)Display the names of programmers whose
names contaion upto 5
107)How many packages were developed by characters.
students who studied in institute that charge the a)
lowest corse fee.
a) 122)How many female programmers knowing
cobol have more than 2 years
108)How many packages were developed by the experience.
person who develped the cheapest package and a)
where did she/he study from.
a) 123)What is the length of the shortest name in
programmer table.
109)In how many packages female programmers a)
are earning more than the male programmer.
a) 124)What is the average development cost of a
package developed in
110)How many packages were developed by the cobol.
most experienced programmer from bdps. a)
a)
125)Display the name,sex,dob(dd/mm/yy
111)List the programmer(from software table) format)for all programmers,
and the institutes they studied including those without using conversion function.
who did not develop any package. a)
a)
126)Who are the programmers who were born on
112)List each prof with the number of the last day of the month.
programmers having that prof and the number of a)
packages developed in that prof.
a) 127)What is the amount paid in salaries of the
male programmers who don't know cobol.
113)List the programmer names(from the a)
programmer table) and the number of packages
each has developed. 128)Display the Title______________________And
a) ______________in descending order of differences.
a)
114)Display the details of those who will have
experience of 2 years of service this year. 129)Display the names of the packages whose
a) names contains more than 1 word.
a)
115)Calculate the amount to be recovered for
those packages whose development cost has not 130)Display the name,job,odj of those month of
yet been recovered. birth & month of joining are the same.
a) a)

116)List the package which has not been sold so


far.
a)

117)Find out the cost of the software developed


by Mary.
a)

118)Display the institute name from the studies


table without duplicates.

You might also like