Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Roles and Stored Object behaviour Oracle
  • 10g oem configuration Oracle
  • mutex in Oracle 10.2.0.2 or Oracle 10g Oracle
  • Clean up Oracle
  • Query to Generate aggregate on every 30 mins. Oracle
  • Temporary Tablespace Information and restriction. Oracle
  • dbms_job.submit example Oracle
  • Finding locked objects Oracle
  • How to know current SID Oracle
  • sess1.sql Oracle
  • initUOCIOTTO.ora Oracle
  • Rename Oracle Instance Name Oracle
  • Global Unique Identifier Generation in Oracle 9.2 SYS_GUID() Oracle
  • scripts to take listener.log backup Linux/Unix
  • Find All internal Parameters 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

  • Drop specific SQL plan baseline – spm Oracle
  • Creating never expiring DB user accounts in Oracle Oracle
  • Resolving RMAN Hung Jobs Oracle
  • Flowers Resize datafiles Oracle
  • switchover for primary database Oracle
  • When to rebuld B-tree index 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 (392)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • load SPM baseline from cursor cache05-Jun-2025
  • Drop all SPM baselines for SQL handle05-Jun-2025
  • Load SPM baseline from AWR05-Jun-2025
  • Drop specific SQL plan baseline – spm05-Jun-2025
  • 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

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • 10g RAC: Troubleshooting CRS Root.sh Problems Oracle
  • AWR license Oracle
  • ENQ: KO – FAST OBJECT CHECKPOINT tips Oracle
  • OEM-troubleshooting on 20-MAY-08 Oracle
  • Wait Based Tuning Step by step with SQL statement Oracle
  • Oracle 10g Installation/Applying Patches Tips Oracle
  • configUOCIOTTO.ora Oracle
  • sql_plan9i.sql Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme