Você está na página 1de 4

1)Display the employee number and annual salary for all employees

Syntax:Select ename,12*(Sal+nvl(comm,0) as annual sal from Emp;



2)Display the Employee no and total salary for all the employees
Syn: Select Empno,ename,Sal,Comm,Sal+nvl(comm,0) Total Sal from Emp;

3)Display the list of employees who have joined the company before 30-JUN-90 after 31-DEC-90.
Syn : Select ename from Emp where hiredate <30-JUN-1990 or hiredate>31-DEC-1990;

4)Display the employees names and working in dept no 10 or 20 or 40 or employees working as
CLERK,SALESMAN or ANALYST.
Syn: Select ename from Emp where deptno in (10,20,30) or job in (CLERK,SALESMAN,ANALYST);

5)Display the total number of employees working in the company.
Syn:Select count (*) from Emp;

6)Display the total salary drawn by ANALYST working in deptno:40
Syn:Select sum(sal) from Emp where Job=ANALYST and deptno=40;

7)Display the various jobs along with total salary of each of the jobs where total salary is greater than
40000
Syn:Select job,sum(sal) from Emp group by job having sum (sal)>40000;

8)Display the employee number and name for employee working as clerk and earning highest salary
among clerks
Syn:Select empno,ename from Emp where job=CLERK and Sal=(Select max(sal) from Emp where
job=CLERK);

9)Display the names of the salesman who earns a salary more than the highest salary of any clerk
Syn:Select ename from Emp
Where job=Salesman and
Sal>(Select max(sal) from Emp
Where job=CLERK);

10)Display those employees whose sal is equal to avg of max and min.
Syn:Select ename from Emp
Where sal=(Select max(sal)+min(sal)/2 from Emp;

11)Select count of employees in each dept where count greater than 3
Syn:Selcet count(*) from Emp
Group by dept no
Having count(dept no)>3;

12)Find out the number of employees whose sal is greater than their manager salary
Syn:Select E.Ename from Emp,emp e
Where Emp.Emp no=E.MGR
And Emp.SAL<E.SAL;

13)Display those Employee who are working in sales or research
Syn:Select Ename from Emp
Where deptno in(Select deptno from dept)
Where dname in (Sales,Research);

14)Display the 10
th
record of Emp table (without using rowid)
Syn:Select * from Emp where rownum<11 miners
Select * from Emp where rownum<10;

15)Select ename if name exists more than once
Syn:Select ename from Emp e
Group by ename having count(*)>1;

16)Display the deptno and total number of employees in each dept
Sy:Select dname,count(ename)from Emp,dept
Where Emp.deptno=dept.deptno
Group by dname;

17)Write a query to delete the repeated rows from Emp table
Syn:Delete from Emp where rowed
Not in(Select min(rowid) from Emp
Group by ename);

18)Display top 3 salaries from Emp
Syn:Select sal from (Select * from Emp rder by Sal Desc)
Where rownum <4;

19)Display 9
th
from Emp table
Syn:Select ename from Emp where
Rowid = (Select rowed from Emp where
Rownum<=10 minus
Select rowid from Emp
Where rownum<10);

2
nd
max salary:
Syn:Select max(sal) from Emp where Sal <1
Select max(sal) from Emp);

5
th
max:
Select *from Emp e where Sal>5(Select
Count (*) from Emp where Sal>e.sal);

20)Display the names of the employees from deptno 10 with sal greater than that of any employee
working in other dept
Syn:Select ename from Emp where deptno=10
And sal>all(Select Sal from Emp
Where deptno not in 10);

21)Display those employees whose salary is more than 3000 after giving 20%discount increment
Syn:Select ename, sal from Emp
Where (sal+sal*2)>3000;

JOIN

22)Display employee name,deptname,sal and comm. For those sal in between 2000 to 5000 while
location is Chicago
Syn:Select ename,dname,sal,comm. From Emp,
Dept where sal between 2000 to 5000
And loc=CHICAGO and
Emp.deptno=dept.deptno;

23)Display those employees whose salary is greater than his manager salary
Syn:Select p.ename from Emp e,emp p
Where e.empno=p.mgr and p.sal>e.sal;

JOIN MORE THAN TWO TABLES

24)Display employee name,job,dept name,manager name,his grade and make out an under dept wise
Syn: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.depno=Dept.deptno
Order by Dname;

25)Display the employee name ,job and his manager.Display also employees who are without managers
Syn:Select e.ename,e.job,emp.ename
As manager from Emp,emp e
Where Emp.Empno(+)=e.mgr;

26)Find out the top 3 salaries
Syn:Select sal from Emp e
Where 3>(select count(*) from Emp
Where e.sal<sal);

27)Finding the lowest 3 salaries
Select sal from emp e
Where 3>(select count(*) from emp
Where e.sal>sal);


28)Find out 3rd lowest sal
Select sal from emp
Where 3=(select count(*) from emp
Where e.sal>sal);

29) Find out 3rd highest sal
Select sal from emp
Where 3=(select count(*) from emp
Where e.sal<sal);

Você também pode gostar