GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 179 of 215    Print  
display deptno wise first three lowest salaries in ascending order of deptno and desc order of salary

  
Total Answers and Comments: 5 Last Update: September 16, 2008     Asked by: lalit.eng.kumar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
May 08, 2008 07:56:29   
Imran_Javed Member Since: May 2008   Contribution: 23    

RE: display deptno wise first three lowest salaries in ascending order of deptno and desc order of salary
SELECT ename sal deptno
FROM
(SELECT ename sal deptno
rank() over(PARTITION BY deptno ORDER BY sal ) low_3
FROM emp)
WHERE low_3 < 3
ORDER BY deptno sal DESC;

 
Is this answer useful? Yes | No
May 09, 2008 23:44:51   
tariq_oracle Member Since: April 2008   Contribution: 11    

RE: display deptno wise first three lowest salaries in ascending order of deptno and desc order of salary
select * from emp a
where
3>
(select count(distinct sal) from emp b
where a.sal> b.sal
and a.deptno b.deptno)
order by sal desc

 
Is this answer useful? Yes | No
June 20, 2008 07:15:32   
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: display deptno wise first three lowest salaries in ascending order of deptno and desc order of salary

[CODE]
SQL> SELECT EMPNO ENAME JOB DEPTNO SAL SAL_ORD
2 FROM
3 (
4 SELECT EMPNO ENAME JOB DEPTNO SAL
5 RANK() OVER(PARTITION BY DEPTNO ORDER BY SAL) SAL_ORD
6 FROM EMP
7 )
8 WHERE SAL_ORD < 3
9 ORDER BY DEPTNO;

EMPNO ENAME JOB DEPTNO SAL SAL_ORD
--------- ---------- --------- --------- --------- ---------
7934 MILLER CLERK 10 1730.3 1
7782 CLARK MANAGER 10 3260.95 2
7839 KING PRESIDENT 10 6655 3
7876 ADAMS CLERK 20 1464.1 1
7566 JONES MANAGER 20 3959.73 2
7788 SCOTT ANALYST 20 3993 3
7902 FORD ANALYST 20 3993 3
7900 JAMES CLERK 30 1264.45 1
7521 WARD SALESMAN 30 1663.75 2
7654 MARTIN SALESMAN 30 1663.75 2
7456 KRISHNA 10000 1

11 rows selected.
[/CODE]


 
Is this answer useful? Yes | No
August 04, 2008 08:49:06   
hiasat Member Since: August 2008   Contribution: 1    

MY first contribution
SELECT empno ename sal
FROM (
select empno ename sal
from emp
order by sal asc
)
WHERE
rownum < 3

EMPNO SAL
--------- ---------
7369 800
7900 950
7876 1100

enjoy!! by HIASAT

 
Is this answer useful? Yes | No
September 16, 2008 09:30:35   
vishnu vardhan reddy Member Since: September 2008   Contribution: 6    

RE: display deptno wise first three lowest salaries in ascending order of deptno and desc order of salary
select e.* from
( select enmae sal
dense_rank()
over(partition by deptno
order by sal) ranksal from emp)e
where e.ranksal< 3
we can use rank fn also but rank fn skips the rank
but never dense_rank() skips rank
so better solution is dense_rank()

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape