Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • tblwopk.sql /* Find Tables Without PK */ Oracle
  • Renaming Oracle Instance Name Oracle
  • runsql_once.ksh Linux/Unix
  • Does DBMS_JOB recompute the NEXT_DATE interval after or before Oracle
  • grep multuple patterns Linux/Unix
  • cur_sql.sql Oracle
  • online_bkup.sql Oracle
  • Gather Stats manually using DBMS_STATS after disabling DBMS_SCHEDULER jobs as previous entry Oracle
  • RMAN : Consistent Backup, Restore and Recovery using RMAN Oracle
  • How to set Processes Parameter Oracle
  • How to stop OCSSD Daemon Oracle
  • 556976.1 Oracle Clusterware: Components installed Oracle
  • Locally Managed Tablespace and Dictionary managed tablespace (LMT-DMT) Oracle
  • Global Unique Identifier Generation in Oracle 9.2 SYS_GUID() Oracle
  • Identical Dblink Issue… 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

  • block_ident.sql Oracle
  • The most important Tuning Notes Oracle
  • ext#.sql Oracle
  • Find_planinfo.sql Oracle
  • DBMS_UTILITY PACKAGE Oracle
  • Good notes for shared pool 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
  • Optimizer SORT Operations Oracle
  • Important Solaris Commands Linux/Unix
  • Jai Shree Ram Oracle
  • SQL_PLAN.sql for checking real execution plan Oracle
  • rm_backup_arch_file.ksh Linux/Unix
  • rm_backup_arch_file.ksh Linux/Unix
  • How to check current redo log progress redo_progress.sql Oracle
  • Single character replacement in Unix Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme