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

Table Order_Name has a column Order_Date which gives the date & Time at which the order is passed.Find the table to write a query to find out the latest order.

5 Answers   Thomson,


what is explain plan?

4 Answers  


How to count the no of records of a table without using COUNT function?

11 Answers   TCS, Tesco,


What is sql catalog?

0 Answers  


How to come back in normal stage in Mutating Table if mutating table is locked or update data?

2 Answers  


What steps server process has to take to execute an update statement?

0 Answers  


Can a varchar be a primary key?

0 Answers  


what is the use of HASH, LIST partitions?

1 Answers   ITC Infotech,


one of the column in my table contains the data like SAL ---- 1000 1000 2000 3000 3000 So my requirement is i want output like SAL --- 1000 2000 3000 it mean i want to delete duplicate rows in the table permanently and i want output in the above formatow should u write query?

13 Answers   Cap Gemini, TCS,


What is the limitation on the block size of pl/sql?

0 Answers  


What is the use of <> sql?

0 Answers  


Define overloaded procedure?

0 Answers  


Categories