Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


i need department wise top 2 employees salary.which logic
i will use

Answers were Sorted based on User's Feedback



i need department wise top 2 employees salary.which logic i will use..

Answer / nitin tomer

Query without using analytic function:

SELECT dept_id, MAX(salary)
FROM EMPLOYEE_DEPT WHERE rowid NOT IN (SELECT MAX(rowid) FROM EMPLOYEE_DEPT GROUP
BY dept_id )
GROUP BY dept_id
UNION
SELECT dept_id, MAX(salary)
FROM EMPLOYEE_DEPT
GROUP BY dept_id;

using row_number() function:

SELECT NAME,DEPT_ID,SALARY,RNM FROM
(SELECT NAME,DEPT_ID,SALARY,ROW_NUMBER()OVER(PARTITION BY DEPT_ID ORDER BY SALARY DESC) AS RNM
FROM EMPLOYEE_DEPT)WHERE RNM<3;

Is This Answer Correct ?    0 Yes 0 No

i need department wise top 2 employees salary.which logic i will use..

Answer / manish gupta

select deptno,sal from (select * from emp order by sal
desc) where rownum<3
union
select deptno,sal from (select * from emp order by sal
desc) where rownum<3 and deptno not in(20);


considering scott table in db.

Is This Answer Correct ?    0 Yes 1 No

i need department wise top 2 employees salary.which logic i will use..

Answer / priyank shah

SELECT * FROM (SELECT ENAME,SAL FROM EMP ORDER BY SAL
DESC)
WHERE ROWNUM < 3

Is This Answer Correct ?    1 Yes 2 No

i need department wise top 2 employees salary.which logic i will use..

Answer / arun

Select top(2)* from table order by salary desc

Is This Answer Correct ?    2 Yes 7 No

i need department wise top 2 employees salary.which logic i will use..

Answer / mukesh kumar

SELECT * FROM (SELECT NAME,SALARY FROM EMP ORDER BY SALARY
DESC)
WHERE ROWNUM < 3

Is This Answer Correct ?    1 Yes 7 No

i need department wise top 2 employees salary.which logic i will use..

Answer / ramya p

select deptno, max(sal) from (select * from emp order by
sal desc)
where rownum < 3
group by deptno
order by max(sal) desc;

Is This Answer Correct ?    5 Yes 12 No

i need department wise top 2 employees salary.which logic i will use..

Answer / ramya p

Select * from emp where sal in
(Select * From (Select sal from emp order by sal desc)
Where rownum < 3) order by sal desc;

Is This Answer Correct ?    6 Yes 18 No

Post New Answer

More SQL PLSQL Interview Questions

Where can I learn sql for free?

0 Answers  


What is CYCLE/NO CYCLE in a Sequence?

2 Answers  


What are different methods to trace the pl/sql code?

0 Answers  


Why is %isopen always false for an implicit cursor?

0 Answers  


Can we call dml statement in function?

0 Answers  


What does select top 1 do in sql?

0 Answers  


What is data control language (dcl)?

0 Answers  


define sql insert statement ? : Sql dba

0 Answers  


What is the difference between numeric and autonumber?

0 Answers  


How do you write an inner join query?

0 Answers  


how would concatenate strings in mysql? : Sql dba

0 Answers  


how to use like conditions? : Sql dba

0 Answers  


Categories