Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Find sort details from Db find_sort.sql Oracle
  • Good notes for shared pool Oracle
  • Finding locked objects Oracle
  • My Minimum Tuning Programs Oracle
  • secure crt settings Linux/Unix
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • Free conference number from http://www.freeconference.com Oracle
  • Oracle 10g Wait Model Oracle
  • Rownum with Order by Oracle
  • adding new line after specific pattern using sed Linux/Unix
  • perf_today.sql Oracle
  • Proc Compilation Oracle
  • Identical Dblink Issue… Oracle
  • My Test Case On 21-OCT-2005 Oracle
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle

Find nth max and min.

Posted on 02-May-2007 By Admin No Comments on Find nth max and min.

First, the query for Max:

SELECT * FROM TAB1 a

WHERE &N = (SELECT count(DISTINCT(b.col1))

FROM TAB1 b WHERE a.col1<=b.col1) Next, the query for Min:
SELECT * FROM TAB1 a

WHERE &N = (SELECT count(DISTINCT(b.col1))

FROM TAB1 b WHERE a.col1>=b.col1)

If N=1 will return first max or first min. N=2 will return second max or min.

Oracle, SQL scripts

Post navigation

Previous Post: DBMS_Shared_pool pinning triggers
Next Post: Changing Instance Name ( No DB_NAME)

Related Posts

  • Standby Database Behavior when a Datafile is Resized on the Primary Database Note:123883.1 Oracle
  • Transfer SQL Profiles from One database to other database. Oracle
  • pvmehta.com SQL scripts
    Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle Oracle
  • Benefits and Usage of RMAN with Standby Databases Oracle
  • Metalink Note: Note:250655.1 : ADDM Basics USING THE AUTOMATIC DATABASE DIAGNOSTIC MONITOR Oracle
  • Pending Distributed Transations Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (388)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (337)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • findinfo.sql (SQL for getting CPU and Active session info)27-May-2025
  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024
  • Reading config file from other folder inside class24-Sep-2024
  • Python class import from different folders22-Sep-2024
  • Transfer SQL Profiles from One database to other database.05-Sep-2024
  • Load testing on Oracle 19C RAC with HammerDB18-Jan-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • find_du.ksh to find # of files, their sizes in current folder and its subdolder Linux/Unix
  • Finding Oracle Patches with opatch Oracle
  • handling filenname with space Linux/Unix
  • TRUNCATE table and disabling referential constraints. Oracle
  • DBMS_UTILITY.ANALYZE_SCHEMA Oracle
  • Reclaim temp tablespace for oracle 8, 8i Oracle
  • V$transaction notes for finding XID composition. Oracle
  • Settting up get_vmstat.sh for colletinf CPU Usage. Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme