Sie sind auf Seite 1von 4

1) To View Every Odd Number of Records:

Select rownum, empno, ename from EMP

Group by rownum, empno, ename

Having mod (rownum, 2) =1;

2) To View Every Even Number of Records:

Select rownum, empno, ename from EMP

Group by rownum, empno, ename having mod (rownum, 2) =0;

3) To Select Duplicate Records:

Select empno from EMP group by empno having count (empno)>1:

4) To Delete Duplicate Rows:

Delete from EMP where rowid not in (select min (rowid) from EMP

Group by empno);

5) To Select First N Number of Rows:

Select rownum, empno, ename from EMP where rownum < n;

6) To Select Last N Number of Rows:


Select * from (select ename, empno, sal, rownum from EMP order by rownum
desc)

Where rownum <=4;

7) To Select Last Row From Table:

Select * from EMP where rowid= (select max (rowid) from EMP);

8) To Select Nth Maximum Salary:

Select * from EMP a where & n = (select count (*) from EMP b where a.sal <
b.sal);

(or)

Select min (sal) from (select sal from EMP order by sal desc)

Where rownum < 6;

9) To Select the Department with Max number of Employees:

Select deptno, count (deptno) from EMP having count (deptno

) = (select max (count (deptno)) from EMP group by deptno)

Group by deptno;

10) To Display EMP with their Manager:

Select a.empno, a.ename, a.mgr, b.ename "manager" from EMP a, EMP b

Where a.mgr =b.empno;


11) To Display the Top 3(n) Earners:

Select rownum as rank, ename, sal from (select ename, sal from EMP order
by sal desc)

Where rownum<=3;

12) To Display the 4 Most Senior Employees:

Select rownum as senior, e.ename, e.hiredate from (select ename, hiredate


from EMP order by hiredate) e where rownum <= 4;

13) To find all the Employees Who earns more than the Average Sal in their
Dept:

Select ename, sal, deptno from EMP outer where sal > (select avg (sal) from
EMP

Where deptno=outer.deptno)

14) To get Rows n through m from the Query:

Select * from (select ename, sal, rownum as rnum from EMP where rownum
<14)
Where rnum between 10 and 13;

15) To get Count of Employees:

Select job, count (*) from EMP group by job;

16) To select nth Row from a Table:

Select * from (select ename, rownum as rnm from EMP where rownum<13)

Where rnm=9;

Das könnte Ihnen auch gefallen