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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you create a unique index?

1033


name 3 ways to get an accurate count of the number of records in a table? : Sql dba

1043


What is a table?

1000


What does the hierarchical profiler does?

1048


What is package in pl sql with an examples?

1020


Which join is default?

936


Is primary key always clustered index?

993


Is sql better than access?

995


What is oracle and pl sql?

1107


which types of join is used in sql widely? : Sql dba

969


how to rename an existing column in a table? : Sql dba

1002


What is an index? What are the types of indexes? How many clustered indexes can be created on a table?

1053


What is exit statement?

1001


what is the difference between nested subquery and correlated subquery?

1028


explain the difference between delete , truncate and drop commands? : Sql dba

1074