Db2

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sajithamol

    #1

    Db2

    How to we calculate the nth maximum value of a column?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sajithamol
    How to we calculate the nth maximum value of a column?
    Suppose you have a table called items with a column called price then to find the item with the third highest price you can try

    [CODE=sql]SELECT * FROM items a WHERE 3 = (SELECT COUNT(DISTINCT( b.PRICE)) FROM items b WHERE a.price <= b.price)[/CODE]

    Comment

    Working...