4
How can I get the value before the MAX
in SQL?
I tried to MAX -1
but it did not work, because the values of the column I want to select the value before the MAX
are not in ascending order.
4
How can I get the value before the MAX
in SQL?
I tried to MAX -1
but it did not work, because the values of the column I want to select the value before the MAX
are not in ascending order.
3
The concept of the former may be relative. I think it solves what you want:
SELECT MAX(coluna) FROM tabela WHERE coluna NOT IN (SELECT MAX(coluna) FROM tabela)
I put in the Github for future reference.
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.
Exactly what I wanted!! Thank you!!!
Browser other questions tagged sql
You are not signed in. Login or sign up in order to post.
Hello @Amandalima, could you show the SQL you tried to do? So it gets easier to help.
– cantoni