How to get the value before MAX in SQL?

4

How can I get the value prior to MAX in SQL?

I have tried MAX -1 but it did not work, because the column values I want to select the value before MAX are not in ascending order.

    
asked by anonymous 04.08.2015 / 18:17

1 answer

3

The concept of anterior can be relative. I think this solves what you want:

SELECT MAX(coluna) FROM tabela WHERE coluna NOT IN (SELECT MAX(coluna) FROM tabela)

You do a search for the maximum and then do another search in the whole without what you found, so the new maximum will be the previous one.

    
04.08.2015 / 18:34