Women in Technology

Hear us Roar



Article:
  SQL Data Types
Subject:   how do we find nth highest in SQL
Date:   2007-11-21 02:20:53
From:   Ani123
Response to: how do we find nth highest in SQL

With qry1 as (Select col1, col2, rownumber() over ()rownum from tablename order by col2 DESC)
select * from qry1 where rownum=6;


This finds the 6th highest;

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • how do we find nth highest in SQL
    2009-10-13 11:57:45  Sandip D [View]

    SELECT DISTINCT (a.sal) FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);
    Enter value for n: 2
    SAL
    ---------
    3700