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.
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.
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.