Sie sind auf Seite 1von 2

top three sales select * from( select * from emp order by sal desc) where rownum<=3; select a.

empno, a.sal from (select * from emp order by sal desc) a where rownum <=3 first ten values in tables select * from (select * from emp order by rowid ) where rownum<=10 How to find out duplicate records in table? Select empno, count (*) from EMP group by empno having count (*)>1; How to delete a duplicate records in a table? delete from emp where rowid not in(select max(rowid) from emp group by empno); delete from emp a where rowid != (select max(rowid) from emp b where a.empno=b. empno); Check with emp1 select rownum as rank,empno,sal from(select empno,sal from emp1 where rowid in(s elect max(rowid) from emp1 group by empno) order by sal); to find max(sal) select * from emp e where &n=(select count(distinct sal) from emp where e.sal<=s al); where n=1,2,3,4... select * from(select ename,sal,rank() over (order by sal desc) ranking from emp) where ranking=n; where n=1,2,3,4 Bottom 10 salaries SELECT ename, sal FROM ( SELECT ename, sal, RANK() OVER (ORDER BY sal) sal_rank FROM emp ) WHERE sal_rank <= 10; Top 10 salaries SELECT ename, sal FROM ( SELECT ename, sal, RANK() OVER (ORDER BY sal DESC) sal_rank FROM emp ) WHERE sal_rank <= 10; TOP TEN SAL WITH DNAME select * from(select * from(select * from emp order by sal desc) where rownum<=1 0) a, dept b where a.deptno=b.deptno To generate serial number: select row_number() over(order by sal desc) as srno,sal,empno from emp; to select the first row in the table select * from emp where rowid=(select min(rowid) from emp)

to select the last row in the table select * from emp where rowid=(select max(rowid) from emp) Top salaries even if sal is repeated 2 times it will be shown. select * from emp where sal in (select sal from (select distinct sal from emp order by sal desc) where rownum <= 7) select * from(select ename,empno,sal,deptno,dense_rank() over(order by sal desc) rank from emp)where rank<=10 To get two values select * from emp e where &m=(select count(distinct sal) from emp where e.sal<=s al) or &n=(select count( distinct sal) from emp where e.sal<=sal) order by sal nod delete duplicate rows which has null values... 1)delete from table_name a where a.rowid > any (select b.rowid from table_name b where a.col1 = b.col1 and a.col2 = b.col2 ) 2)delete from table_name a where a.rowid > any (select b.rowid from table_name b where (a.col1 = b.col1 or (a.col1 is null and b.col1 is null)) and (a.col2 = b.col2 or (a.col2 is null and b.col2 is null)) ) ; To generate serial number select row_number() over(order by sal desc) as srno,sal,empno from emp;

Das könnte Ihnen auch gefallen