You are on page 1of 13

SQL Queries

1)Display the details of all employees


a)select * from emp;

17)Display the name of the current user.


a)show user

2)Display the depart informaction from department table


a)select * from dept;

18)Display the names of employees working in depart number 10 or


20 or
40 or employees working as CLERKS, SALESMAN or ANALYST.
a) Select ename from emp where deptno in(10,20,40) or job
in('CLERKS','SALESMAN','ANALYST');

3)Display the name and job for all the employees


a)select ename,job from emp;
4)Display the name and salary for all the employees
a)select ename,sal from emp;
5)Display the employee no and totalsalary for all the employees
a)select empno,sal+comm as total from emp group by empno;
6)Display the employee name and annual salary for all employees.
a)select ename,sal * 12 as annualsalary from emp;
7)Display the names of all the employees who are working in depart
number 10.
a)select emame from emp where deptno=10;
8)Display the names of all the employees who are working as clerks
and
drawing a salary more than 3000.
a)select ename from emp where job='CLERKS' and sal>3000;
9)Display the employee number and name who are earning comm.
a)select empno,ename from emp where comm is not null;
10)Display the employee number and name who do not earn any
comm.
a)select empno,ename from emp where comm is null;

19) Display the names of employees whose name starts with


alphabet S.
a)select ename from emp where ename like 'S%';
20) Display the Employee names for employees whose name ends
with Alphabet S.
a) Select ename from emp where ename like '%S';
21) Display the names of employees whose names have second
alphabet A in their names.
a) Select ename from EMP where ename like '_A%';
22) select the names of the employee whose names is exactly five
Characters in length.
a) select ename from emp where length(ename)=5;
23) Display the names of the employee who are not working as
MANAGERS.
a) Select ename from emp where job not in ('MANAGER');
24)Display the names of the employee who are not working as
SALESMAN OR CLERK OR ANALYST.
A)select ename from emp where job not
in('SALESMAN','CLERK','ANALYST');

11)display the names of employees who are working as


clerks,salesman or
analyst and drawing a salary more than 3000.
A)select ename from emp where job='CLERK' OR
JOB='SALESMAN' OR
JOB='ANALYST' AND SAL>3000;

25) Display all rows from EMP table. The system should wait after
every Screen full of information.
a) Set pause on

12)display the names of the employees who are working in the


company
for the past 5 years;
a)select ename from emp where
to_char(sysdate,'YYYY')-to_char(hiredate,'YYYY')>=5;

27) Display the total salary beiging paid to all employees.

13)Display the list of employcees who have joined the company


before
30-JUN-90 or after 31-DEC-90.
a)select ename from emp where hiredate < '30-JUN-1990' or hiredate
>
'31-DEC-90';

26) Display the total number of employee working in the company.


a) Select count (*) from EMP;

a)select sum(sal) from emp;


28)Display the maximum salary from emp table.
a)select max(sal) from emp;
29)Display the minimum salary from emp table.
a)select min(sal) from emp;
30)Display the average salary from emp table.
a)select avg(sal) from emp;

14)Display current Date.


a)select sysdate from dual;

31)Display the maximum salary being paid to CLERK.


a)select max(sal) from emp where job='CLERK';

15)Display the list of all users in your database(use catalog table).


a)select username from all_users;

32)Display the maximum salary being paid to depart number 20.


a)select max(sal) from emp where deptno=20;

16)Display the names of all tables from current user;


a)select tname from tab;

33)Display the minimum salary being paid to any SALESMAN.


a)select min(sal) from emp where job='SALESMAN';

34)Display the average salary drawn by MANAGERS.


a)select avg(sal) from emp where job='MANAGER';
35)Display the total salary drawn by ANALYST working in depart
number
40.
a)select sum(sal) from emp where job='ANALYST' and deptno=40;

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;

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.
a)select job,count(empno) from emp group by job having
count(job)>3

37)Display the names of the employee in descending order of salary.


a)select ename from emp order by sal desc;

51)Display the name of the empployee who earns highest salary.


a)select ename from emp where sal=(select max(sal) from emp);

38)Display the names of the employee in order of employee name.


a)select ename from emp order by ename;

52)Display the employee number and name for employee working as


clerk
and earning highest salary among clerks.
a)select empno,ename from emp where where job='CLERK' and
sal=(select
max(sal) from emp where job='CLERK');

39)Display empno,ename,deptno,sal sort the output first base on


name
and within name by deptno and with in deptno by sal.
a) select empno,ename,deptno,sal from emp
order by ename,deptno,sal
40)Display the name of the employee along with their annual
salary(sal*
12).The name
of the employee earning highest annual salary should apper first.
a)select ename,sal*12 from emp order by sal desc;
41)Display name,salary,hra,pf,da,total salary for each employee. The
output should be in
the order of total salary,hra 15% of salary,da 10% of salary,pf 5%
salary,total salary will be(salary+hra+da)-pf.
a)select ename,sal,sal/100*15 as hra,sal/100*5 as pf,sal/100*10 as
da,sal+sal/100*15+sal/100*10-sal/100*5 as total from emp;
42)Display depart numbers and total number of employees working in
each
department.
a)select deptno,count(deptno)from emp group by deptno;
43)Display the various jobs and total number of employees within
each
job group.
a)select job,count(job)from emp group by job;
44)Display the depart numbers and total salary for each department.
a)select deptno,sum(sal) from emp group by deptno;
45)Display the depart numbers and max salary for each department.
a)select deptno,max(sal) from emp group by deptno;
46)Display the various jobs and total salary for each job
a)select job,sum(sal) from emp group by job;
47)Display the various jobs and total salary for each job
a)select job,min(sal) from emp group by job;
48)Display the depart numbers with more than three employees in
each
dept.
a)select deptno,count(deptno) from emp group by deptno having

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 ename from emp where deptno=(select deptno from dept


where
LOC='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');

74)Display your age in days.


a)select to_date(sysdate)-to_date('10-sep-77')from dual

61)Display the names of employees from department number 10 with


salary
grether than that of any employee working in other department.
a)select ename from emp where deptno=10 and sal>any(select sal
from emp
where deptno not in 10).
62)Display the names of the employees from department number 10
with
salary greater than that of all employee working in other departments.
a)select ename from emp where deptno=10 and sal>all(select sal
from emp
where deptno not in 10).
63)Display the names of the employees in Uppercase.
a)select upper(ename)from emp
64)Display the names of the employees in Lowecase.
a)select lower(ename)from emp
65)Display the names of the employees in Propercase.
a)select initcap(ename)from emp;
66)Display the length of Your name using appropriate function.
a)select length('name') from dual
67)Display the length of all the employee names.
a)select length(ename) from emp;
68)select name of the employee concatenate with employee number.
select ename||empno from emp;
69)User approprate function and extract 3 characters starting from 2
characters from the following string 'Oracle'. i.e the out put should be
'ac'.
a)select substr('oracle',3,2) from dual

75)Display your age in months.


a)select months_between(sysdate,'10-sep-77') from dual
76)Display the current date as 15th Augest Friday Nineteen Ninety
Saven.
a)select to_char(sysdate,'ddth Month day year') from dual
77)Display the following output for each row from emp table.
78)scott has joined the company on wednesday 13th August ninten
nintey.
a)select ENAME||' HAS JOINED THE COMPANY ON '||
to_char(HIREDATE,'day
ddth Month year') from EMP;
79)Find the date for nearest saturday after current date.
a)SELECT NEXT_DAY(SYSDATE,'SATURDAY')FROM DUAL;
80)display current time.
a)select to_char(sysdate,'hh:MM:ss') from dual.
81)Display the date three months Before the current date.
a)select add_months(sysdate,3) from dual;
82)Display the common jobs from department number 10 and 20.
a)select job from emp where deptno=10 and job in(select job from
emp
where deptno=20);
83)Display the jobs found in department 10 and 20 Eliminate
duplicate
jobs.
a)select distinct(job) from emp where deptno=10 or deptno=20
or
select distinct(job) from emp where deptno in(10,20);
84)Display the jobs which are unique to department 10.
a)select distinct(job) from emp where deptno=10

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;

71)Replace every occurance of alphabhet A with B in the string


Allens(use translate function)
a)select translate('Allens','A','B') from dual

86)Display the details of those employees who are in sales


department
and grade is 3.

72)Display the informaction from emp table.Where job manager is


found
it should be displayed as boos(Use replace function).
a)select replace(JOB,'MANAGER','BOSS') FROM EMP;

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);

73)Display empno,ename,deptno from emp table.Instead of display


department numbers display the related department name(Use
decode function).

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';

99)Update the salary of each employee by 10% increment who are


not eligiblw for commission.
a)update emp set sal=sal+sal*10/100 where comm is null;
100)SELECT those employee who joined the company before 31dec-82 while their dept location is newyork or Chicago.
a)SELECT EMPNO,ENAME,HIREDATE,DNAME,LOC FROM
EMP,DEPT WHERE
(EMP.DEPTNO=DEPT.DEPTNO)AND
HIREDATE <'31-DEC-82' AND DEPT.LOC IN('CHICAGO','NEW
YORK');
101)DISPLAY EMPLOYEE NAME,JOB,DEPARTMENT,LOCATION
FOR ALL WHO ARE
WORKING AS MANAGER?
A)select ename,JOB,DNAME,LOCATION from emp,DEPT where mgr
is not null;
102)dISPLAY THOSE EMPLOYEES WHOSE MANAGER NAME IS
JONES? --[AND ALSO
DISPLAY THEIR MANAGER NAME]?
A) SELECT P.ENAME FROM EMP E, EMP P WHERE
E.EMPNO=P.MGR AND
E.ENAME='JONES';
103)Display name and salary of ford if his salary is equal to hisal of
his grade
a)select ename,sal,grade from emp,salgrade where sal between losal
and
hisal
and ename ='FORD' AND HISAL=SAL;
104)Display employee name,job,depart name ,manager name,his
grade and
make out an under department wise?
a)SELECT E.ENAME,E.JOB,DNAME,EMP.ENAME,GRADE FROM
EMP,EMP
E,SALGRADE,DEPT
WHERE EMP.SAL BETWEEN LOSAL AND HISAL AND
EMP.EMPNO=E.MGR AND
EMP.DEPTNO=DEPT.DEPTNO ORDER BY DNAME
105)List out all employees name,job,salary,grade and depart name
for every one in the company except 'CLERK'.Sort on salary display
the highest salary?
a)SELECT ENAME,JOB,DNAME,SAL,GRADE FROM
EMP,SALGRADE,DEPT WHERE
SAL BETWEEN LOSAL AND HISAL AND
EMP.DEPTNO=DEPT.DEPTNO AND JOB NOT
IN('CLERK')ORDER BY SAL ASC;
106)Display the employee name,job and his manager.Display also
employee who are without manager?
a)select e.ename,e.job,eMP.ename AS Manager from emp,emp e
where emp.empno(+)=e.mgr
107)Find out the top 5 earners of company?
a)SELECT DISTINCT SAL FROM EMP E WHERE 5>=(SELECT
COUNT(DISTINCT SAL)
FROM EMP A WHERE A.SAL>=E.SAL)ORDER BY SAL DESC;
108)Display name of those employee who are getting the highest
salary?

a)select ename from emp where sal=(select max(sal) from emp);


109)Display those employee whose salary is equal to average of
maximum
and minimum?
a)select ename from emp where sal=(select max(sal)+min(sal)/2 from
emp);
110)Select count of employee in each department where count
greater than 3?
a)select count(*) from emp group by deptno having count(deptno)>3
111)Display dname where at least 3 are working and display only
department name?
a)select distinct d.dname from dept d,emp e where
d.deptno=e.deptno and
3>any (select count(deptno) from emp group by deptno)
112)Display name of those managers name whose salary is more
than average salary of his company?
a)SELECT E.ENAME,EMP.ENAME FROM EMP,EMP E WHERE
EMP.EMPNO=E.MGR AND
E.SAL>(SELECT AVG(SAL) FROM EMP);
113)Display those managers name whose salary is more than
average salary of his employee?
a)SELECT DISTINCT EMP.ENAME FROM EMP,EMP E WHERE
E.SAL <(SELECT AVG(EMP.SAL) FROM EMP
WHERE EMP.EMPNO=E.MGR GROUP BY EMP.ENAME) AND
EMP.EMPNO=E.MGR;
114)Display employee name,sal,comm and net pay for those
employee whose net pay is greter than or equal to any other
employee salary of
the company?
a)select ename,sal,comm,sal+nvl(comm,0) as NetPay from emp
where sal+nvl(comm,0) >any (select sal from emp)
115)Display those employees whose salary is less than his manager
but more than salary of any other manager?
a)
116)Display all employees names with total sal of company with each
employee name?
a)SELECT ENAME,(SELECT SUM(SAL) FROM EMP) FROM EMP;
117)Find out last 5(least)earners of the company.?
a)SELECT DISTINCT SAL FROM EMP E WHERE 5>=(SELECT
COUNT(DISTINCT SAL)
FROM EMP A WHERE A.SAL<=E.SAL)ORDER BY SAL DESC;
118)Find out the number of employees whose salary is greater than
their manager salary?
a)SELECT E.ENAME FROM EMP ,EMP E WHERE
EMP.EMPNO=E.MGR AND
EMP.SAL<E.SAL;
119)Display those manager who are not working under president but
they are working under any other manager?
a)
120)Display those department where no employee working?
a)select dname from emp,dept where emp.deptno not in(emp.deptno)

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;

136)Delete those records where no of employees in a particular


department is less than 3.
a)delete from emp where deptno=(select deptno from emp
group by deptno having count(deptno)<3);
137)Display the department name the no of characters of which
is equal to no of employee in any other department.
a)
138)Display the name of the department where no employee working.
a)
139)Display those employees who are working as manager.
a)
140)Count the no of employees who are working as manager(using
set
operations).
a)
141)Display the name of the dept those employee who joined the
company
on the same date?
a)
142)Display those employees whose grade is equal to any number of
sal
but not equal to first number of sal?
a)
143)Count the no of empployee working as manager using set
operaction?
a)
144)display the name of the employees who joined the same date.
a)
145)Display the manager who is having maximum number of
employees working under him?
a)
146)list out employee name and salary increased by 15% and
expressed as whole number of Dollars?
a)
147)Produce the output of the emp table "EMPLOYEE AND JOB" for
ename and job?
a)
148)List all employee with hiredate in the format 'june 4 1988'?
a)
149)Print lost of employees displaying "just salary" if more than 1500
if exactly 1500 display 'On target' if less than 1500 Display below
1500?
A)select ename,sal,(case when sal>1500 then 'Below_target' when
sal=1500 then 'On_targer' when sal<1500 then
'less than target' else 'kkkkk' end )from emp
150)WHICH query to calcuate the length of time any employee has
been with the company?

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)

180)Find all departments which have more than 3 employees?


a)
181)Check whether employees number are unique?
a)
182)List lowest paid employees working for each manager exclude
any
groups where the minimum salary less than 1000. Sort the output by
salary?
a)
183)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?
a)

184)If an employee is taken by you today in your organisation.


And it is a policy in 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 employees has To wait for a review?
a)
185)Display employee name and his salary whose salary is greater
than highest average of department number?
a)SELECT SAL FROM EMP WHERE SAL>(SELECT
MAX(AVG(SAL)) FROM EMP GROUP BY
DEPTNO);
186)Display the 10th record of emp table(without using rowid)
a)
SELECT * FROM EMP WHERE ROWNUM<11
MINUS
SELECT * FROM EMP WHERE ROWNUM<10
187)Display the half of the ename's in upper case and remaining
lowercase?
a)
SELECT
SUBSTR(LOWER(ENAME),1,3)||
SUBSTR(UPPER(ENAME),3,LENGTH(ENAME)) FROM EMP;
188.
Display the 10th record of emp table without using group
by and rowid?
A)
SELECT * FROM EMP WHERE ROWNUM<11
MINUS
SELECT * FROM EMP WHERE ROWNUM<10
189.
Delete the 10th record of emp table.
A)
DELETE FROM EMP WHERE EMPNO=(SELECT
EMPNO FROM EMP WHERE ROWNUM<11
MINUS
SELECT EMPNO FROM EMP WHERE ROWNUM<10)
190.
a)

Create a copy of emp table;


create table new_table as select * from emp where 1=2;

191.
Select ename if ename exists more than once.
a)
select ename from emp e group by ename having
count(*)>1;
192.
a)

Display all enames in reverse order?(SMITH:HTIMS).


SELECT REVERSE(ENAME)FROM EMP;

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)

Display those employees name as follows


A ALLEN
B BLAKE
SELECT SUBSTR(ENAME,1,1),ENAME FROM EMP;

196.
emp;
A)

List out the employees ename,sal,PF(20% OF SAL) from

197.
inserting.
A)

Display RSPS from emp without using updating

198.
A)

Create table emp with only one column empno;


create table emp as select empno from emp where 1=2;

199.
a)

Add this column to emp table ename vrachar2(20).


alter table emp add(ename varchar2(20));

200.
now.
a)

Oops I forgot give the primary key constraint. Add in

Add column called as mgr to your emp table;


alter table emp add(mgr number(5));

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)

Add deptno column to your emp table;


alter table emp add(deptno number(5));

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]

SELECT ENAME,SAL,SAL*.2 AS PF FROM EMP;

alter table emp add primary key(empno);

201.
Now increase the length of ename column to 30
characters.
a)
alter table emp modify(ename varchar2(30));
202.

206.
a)

Add salary column to emp table.


alter table emp add(sal number(10));

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(+)

a)select to_char(dob,'YY'),count(dob) from programer group by


to_char(dob,'YY');

219.
Display employee name and his manager name.
a)
select p.ename,e.ename from emp e,emp p where
e.empno=p.mgr;

6)Display the number of people joined in each month.


a)select to_char(dob,'MM'),count(dob) from programer group by
to_char(dob,'MM');

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;

7)Display the language-wise count of prof1.


a)select prof1,count(prof1) from programer group by prof1;

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.

Give the following commands:


Delete from emp where job 'clerk'
Inset into emp
without giving any further commands move to another client
system and log into the same user give the following command
select * from emp.
1.Are the above changes reflected in this user?(yes)
2.Goto your first system, and give commit. Come back to
second
system and give the following command
Select * from emp.
Ans:Changes Will be affect in second system.
Q)Write a Query To Delete The Repeted Rows from emp table;
a)delete from emp where rowid not in(select min(rowid)from emp
group by
ename)
/

Plain Text Attachment [ Download File | Save to my Yahoo!


Briefcase ]
QUERIES BASED ON PROGRAMMER, SOFTWARE & STUDIES
TABLES
______________________________________________________
1)Display the number of packages developed in each.
a)select count(title) from software group by dev_in;
2)Display the number of packages developed by each person.
a)select count(title) from software group by pname;
3)Display the number of male and female programmers.
a)select sex,count(sex) from programer group by sex;
4)Display the costiest package and the highest selling package
developed in each language.
a)select dev_in,max(dcost),max(sold) from software group by dev_in;
5)Display the number of people born in each year.

8)Display the number of people in each salary group.


a)select salary,count(salary) from programer group by salary;
9)Display the numeber of people in each institute.
a)select count(inst) from studies group by inst;
10)Display the number of people who studied in each group.
a)select count(course) from studies group by course;
11)Display the Total development cost of the packages developed in
each
language.
a)select dev_in,sum(dcost) from software group by dev_in;
12)Display the total selling cost of the packages developed in each
language.
a)
13)Display the cost of package developed by each programmer.
a)select pname,scost+dcost from software;
14)Display the sales value of the packages developed by each
programmer.
a)
15)Display the number of packages sold by each programmer.
a)select count(pname) from software group by pname;
16)Display the sales cost of the packages developed by each
programmer
languagewise.
a)
17)Display the language name with average development cost and
selling
cost.
a)
18)Display the name of each programmer with the costiest package
cheapest package
developed by him/her.
a)
19)Display each institute name with number of courses and average
cost
per course.
a)select inst,count(course),avg(ccost) from studies group by inst;
20)Display each institute name with number of students.
a)select inst,count(inst)from studies group by inst;
21)Display the names of male programmers.
a)select pname from programer where sex='M';

22)Display the programmers name and packages developed by


him/her.
a)select pname,title from software;
23)Display the number of packages in each language, except c & c+
+.
a)select count(title) from software where dev_in not in('C','Cpp')
group by dev_in;

35)Which female programmer earining more than 3000 does not


know c,c++,oracle or dbase.
a)select pname from programer where sex='F' and salary>3000 and
prof1 not in('C','Cpp','Oracle','Dbase') and prof2 not
in('C','Cpp','Oracle','Dbase') ;
36)Find out the average selling cost for packages developed in
pascal.
a)select avg(scost * sold) from software where dev_in='Pascal';

24)Display the number of packages in each language for which


development cost is greater than
1000.
a)select count(title) from software where dcost>1000 group by
dev_in;

37)Display the names and ages of all the programmers.


a)select pname,(sysdate-dob)/365 as age from programer.

25)Display the average difference between Scost and Dcost for each
lnaguage.
a)select avg(scost-dcost) from software;

39)Display the name and date of birth of all programmers born in


january.
a)select pname,dob from programer where
to_char(dob,'MON')='JAN';

26)Display highest,lowest and average salaries for those earning


more
than 2000.
a)select max(salary),min(salary),avg(salary) from programer where
salary>2000;
27)Display the total scost,dcost and amount to be recovered for each
programmer
by those whose dcost has not yet been recovered.
a)
28)Who is the highest paid c programmer.
a)select pname,salary from programer where salary=(select
max(salary)
from programer where prof1='C' or prof2='C');
29)Who is the highest paid female cobol programmer.
a)select pname,salary from programer where salary=(select
max(salary)
from
programer where sex='F' and prof1='Cobol' or prof2='Cobol');
30)Display the names of the highest paid programmer for each
language
prof1.
a)select pname from programer where salary in(select max(salary)
from
programer group by prof1)
31)Who is the least experienced programmer.
a)select min(doj)from programer;
32)Who is the most experienced programmer in PASCAL.
a)select max(doj)from programer where prof1='Pascal' or
prof2='Pascal';
33)Which language is known by only one programmer.
a)
34)Who is the youngest programmer knowing dbase.
a)select pname from programer where dob=(select max(dob) from
programer
where prof1='Dbase' or prof2='Dbase');

38)Display the names of those who have done the DAP course.
a)select pname from studies where course='DAP';

40)Display the lowest course fee.


a)SELECT MIN(CCOST) FROM STUDIES;
41)How many programmer have done the PGDCA course.
a)SELECT COUNT(COURSE) FROM STUDIES WHERE
COURSE='PGDCA';
42)How much revenue has been earned through the sale of
packages
developed.
a)SELECT SUM(SOLD*SCOST) FROM SOFTWARE;
43)Display the details of the software developed by RAMESH.
a)SELECT * FROM SOFTWARE WHERE PNAME='RAMESH';
44)How many programmers studied at SABHARI.
a)SELECT COUNT(COURSE) FROM STUDIES WHERE
INST='SABHARI';
45)Display the details oF packages whose sales crossed the 2000
mark.
a)SELECT * FROM SOFTWARE WHERE SOLD>2000;
46)Find out the number of copies, which should be sold in order to
recovered the
development cost of each packages.
a)
47)Display the details of packages for which development cost has
been recovered.
a)
48)What is the price of the costiest software developed in Basic.
a)SELECT SCOST FROM SOFTWARE WHERE SCOST=(SELECT
MAX(SCOST) FROM
STUDIES WHERE DEV_IN='BASIC');
49)How many packages are developed in Dbase.
a)SELECT COUNT(TITLE) FROM STUDIES WHERE
DEV_IN='DBASE';
50)What is the average coursefee.
a)SELECT AVG(CCOST) FROM STUDIES;

51)Display the details of programmers knowing c.


a)SELECT * FROM PROGRAMER WHERE PROF1='C' or prof2='C';
52)How many programmers know either cobol or pascal.
a)SELECT count(pname) FROM PROGRAMER WHERE
PROF1='Cobol' or prof2='Pascals';
53)How many programmers do not know pascal & c.
a)SELECT count(pname) FROM PROGRAMER WHERE PROF1 not
in('C','Pascal')and prof2 not in('C','Pascal')
54)How old is the oldest male programmer.
a)select max(sysdate-dob)/365 from programer where sex='M';
55)What is the average age of female programmers.
a)select avg(sysdate-dob)/365 from programer where sex='F'
56)Calculate the experience in years for each programmer and
siplay
along with the names in descending order.
a)select pname,(sysdate-doj)/365 from programer order by pname
desc;
57)Who are the programmers who celebrate their birthdays during
the current month.
a)select pname from programer where
to_char(dob,'mm')=to_char(sysdate,'mm');
58)How many female programmers are there.
a)select count(*) from programer where sex='F';
59)What are the language known by the male programmers.
a)select prof1,prof2 from programer where sex='M';
60)What is the average salary.
a)select avg(salary) from programer;
61)How many people draw between 2000 and 4000.
a)select count(*) from programer where salary between 2000 and
4000;
62)Display the details of those who do not know clipper,cobol or
pascal.
a)select * from programer where prof1 not
in('Clipper','Cobol','Pascal')
and prof2 not in('Clipper','Cobol','Pascal');
63)Which institute has maximum number of students.
a)
64)Which course has been done by the maximum number of
students.
a)
65)Display the name of the institue and course which has below
average
course fee.
a)select inst,course from studies where ccost<(select avg(ccost) from
studies);

a)select course,inst from studies where ccost=(select max(ccost)


from
studies)
68)Which course has less than the average number of students.
a)
69)Display the names of the courses whose fees are within 1000/- of
the
course.
a)select course from studies where ccost<1000;
70)Which package has the highest development cost.
a)select title from software where dcost=(select max(dcost) from
software);
71)Which package has lowest selling price.
a)select title from software where dcost=(select min(dcost) from
software)
72)Who developed the package that has sold the least number of
copies.
a)select pname from software where sold=(select min(sold)from
software);
73)Which language was used to develop the package having highest
cost.
a)select dev_in from software where dcost=(select max(dcost)from
software);
74)How many copies of the packages that has the least difference
between developemt and selling cost were sold.
a)
75)Which language was used to develop the highest number of
packages.
a)
76)Which programmer has developed the highest number of
packages.
a)
77)Who is the author of costliest package.
a)select pname from software where dcost=(select min(dcost) from
software);
78)Display the names of the packages which is sold less than the
average.
a)select title from software where sold<(select avg(sold) from
software);
79)Who are the authors of the packages which have recovered more
than double the development cost.
a)
80)Who is the youngest male programmer born in 1965.
a)select pname from programer where dob=(select max(dob) from
programer where sex='M' and to_char(dob,'YYYY')=1965);

66)Which is the costiest course.


a)select course from studies where ccost=(select max(ccost) from
studies);

81)Who is the oldest female programmer who joined in 1992.


a)select pname from programer where dob=(select max(dob) from
programer where sex='F' and to_char(doj,'YYYY')=1992);

67)Which institute conducts the costiest course.

82)In which year were the most number of programmers were born.

a)

a)

83)In which language are most of the programmers proficient.


a)

99)Who are the programmer who have the same Prof.2.


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')

100)Display the total sales value of software, institute wise.


a)

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)

101)In which institute is the person who developed the costilest


package.
a)
102)Which language listed in prof1 and prof2 has not been used to
develop any package.
a)
103)How much does the person who developed the highest selling
package earn and what course did he/she undergo.
a)
104)How many months will it take for each programmer to recover
the cost of the course he/she underwent.
a)
105)Which is the constiest package developed by a person with
udnder 5 years Experience.
a)
106)What is the average salary for those whose softwares sales
value is more than 50000.
a)
107)How many packages were developed by students who studied in
institute that charge the lowest corse fee.
a)
108)How many packages were developed by the person who
develped the cheapest package and where did she/he study from.
a)
109)In how many packages female programmers are earning more
than the male programmer.
a)
110)How many packages were developed by the most experienced
programmer from bdps.
a)
111)List the programmer(from software table) and the institutes they
studied including those who did not develop any package.
a)

95)Display the details of the software that was developed in the


language which is neither the first nor the second proficiency of the
programmers.
a)

112)List each prof with the number of programmers having that prof
and the number of packages developed in that prof.
a)

96)Display the name of the programmers who have not developed


any package.
a)

113)List the programmer names(from the programmer table) and the


number of packages each has developed.
a)

97)What is the total cost of the software developed by programmer by


apple.
a)

114)Display the details of those who will have experience of 2 years


of service this year.
a)

98)Who are the programmer who joined in the same day.

115)Calculate the amount to be recovered for those packages whose


development cost has not yet been recovered.
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.
a)
119)How many different courses are mentioned in the studies table.
a)
120)Display the names of the programmers whose names contain 2
concurrence of the.
a)
121)Display the names of programmers whose names contaion upto
5
characters.
a)
122)How many female programmers knowing cobol have more than
2 years
experience.
a)
123)What is the length of the shortest name in programmer table.
a)
124)What is the average development cost of a package developed
in
cobol.
a)
125)Display the name,sex,dob(dd/mm/yy format)for all programmers,
without using conversion function.
a)
126)Who are the programmers who were born on the last day of the
month.
a)
127)What is the amount paid in salaries of the male programmers
who don't know cobol.
a)
128)Display the Title______________________And
______________in descending order of differences.
a)
129)Display the names of the packages whose names contains more
than 1 word.
a)
130)Display the name,job,odj of those month of birth & month of
joining are the same.
a)

You might also like