Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • SYSOPER Mystery Oracle
  • How to connect to Oracle Database with Wallet with Python. Oracle
  • proc.sql Oracle
  • refre.sql Oracle
  • Find Multiple levels of object dependencies : depen.sql Oracle
  • Session_info.ksh Linux/Unix
  • How to find the real execution plan and binds used in that explain plan in Oracle 10g?? Oracle
  • Creating never expiring DB user accounts in Oracle Oracle
  • Generate SSH without password authentication. Linux/Unix
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • useful dg links Oracle
  • Formatter Explain plan Output 1 Oracle
  • Roles and Stored Procs II Oracle
  • RMAN : Consistent Backup, Restore and Recovery using RMAN Oracle
  • Parallel DML 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

  • Find Plan Hash value fphv.sql Oracle
  • compile_inv.sql Oracle
  • ORA-01220 Oracle
  • Oracle Statspack survival Guide Oracle
  • How to find pinned objects from shared pool. (pinned via dbms_shared_pool.keep) Oracle
  • get_vmstat_linux Oracle

Leave a Reply Cancel reply

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

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (397)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (345)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • track_autoupgrade_copy_progress.sql01-Apr-2026
  • refre.sql for multitenant01-Apr-2026
  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026
  • Complete Git Tutorial for Beginners25-Dec-2025
  • Postgres DB user and OS user.25-Dec-2025
  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • replace alphabets using sed Linux/Unix
  • Follwoing korn shell is used to move files from source folder to destination folder and gzip it in destination folder. mv_iotto.ksh Linux/Unix
  • Reading parameter file and printing Linux/Unix
  • Oracle10g – Using SQLAccess Advisor (DBMS_ADVISOR) with the Automatic Workload Repository Oracle
  • How to see which patches are applied. Oracle
  • Library cahe Latches and internal explaination Oracle
  • Distributed Transaction Troubleshooting. Oracle
  • CPU speed on Linux Linux/Unix

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme