i have a table with 3 columns country,empname,salary and i want the query for get the  name of the employees who is getting top 2 nd highest salary for individual country?
Thanks in advance 

Answer Posted / krish

Query to get 1st max salary from each dept
 
SELECT maxsal, 
       deptno, 
       ename 
FROM   ( 
                SELECT   Max(sal) OVER (partition BY detpno ORDER BY sal)        AS maxsal, 
                         row_number over (partition BY detpno ORDER BY sal DESC) AS id, 
                         ename, 
                         deptno 
                FROM     emp) 
WHERE  id=1;

just place id=2 instead of id=1 for second max salary 
if ur are expecting more than 1 records with max sal 
replace ROW_NUMBER with DENSE_RANK()

http://netezzamigration.blogspot.com/2014/10/analytic-functions-in-netezza.html

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Name the types of report?

559


Can you define fan trap?

757


What is the use of report studio?

615


hi..i'm searching on cognos.i want to know some real time explanation..persons who have real time exp and who r searching in this field..can u send ur mail-id..my mail-id is dhaanuus@gmail.com..hope u will respond as soon as possible..

1460


Why cognos decision stream is used?

640






What is meant by junk dimension?

575


What are the advantages of shortcuts?

537


What is the advantage of using shortcuts?

644


How Metrics Studio is better than Report Studio?

2034


What are the considerations regarding performance kept in mind while setting up cognos?

566


Looking for IBM COGNOS Certification C1000-065 , C2020-605 , C2090-621 , C2090-623 Dumps?

650


What is model?

559


What is the difference between ‘macro’ and ‘prompt?

555


How can reports be bursted based on two groups? I want to schedule to burst a report based on product line and years and I need the burst report for every product line and every year. How can this be done? Please help..

1559


what are the names of the reports that you prepared?

630