Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Exadata Basics Oracle
  • good linux notes Linux/Unix
  • New Latest Param.sql for finding all hidden parameters also Oracle
  • Small sample shell program Linux/Unix
  • 276434.1 Modifying the VIP or VIP Hostname of a 10g or 11g Oracle Clusterware Node Oracle
  • Rename Oracle Instance Name Oracle
  • setting prompt display with .profile Linux/Unix
  • Rman Notes -1 Oracle
  • How to know current SID Oracle
  • pvm_rbs1.sql (to collect rbs info from db) Oracle
  • sql_doing_fts.sql Oracle
  • Clean up Oracle
  • logminer and my_lbu Oracle
  • My Minimum Tuning Programs Oracle
  • Useful Solaris Commands on 28-SEP-2005 Linux/Unix

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

  • USE_NL and INDEX hints example Oracle
  • How To Transfer Passwords Between Databases (ref note: 199582.1) Oracle
  • oracle fast start failover best practice Oracle
  • Processes Parameter decision Oracle
  • v$backup.status information Oracle
  • eplan.sql 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
  • UTL_FILE test program Oracle
  • How to find who is using which Rollback segment and how many rows or blocks in that rollback segments, Oracle
  • CPU Core related projections AWS
  • Database logon trigger issue Oracle
  • 284785.1 How to check RAC Option is currently linked into the Oracle Binary Oracle
  • Find sort details from Db find_sort.sql Oracle
  • newupload.html PHP/MYSQL/Wordpress
  • standard Monitoring – 1 Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme