Reverse SQL ordering

Asked

Viewed 475 times

0

Code sorting of a select can be done in reverse?

Example:

As the last number of the first element is less it comes first and for tiebreaker criterion the second seventeen will be checked, just as in the normal ordination, but as informed, unlike.

1º = 58 95 52

2º = 56 84 55 ...

  • 1

    Would be the ORDER BY coluna DESC looking for?

  • Robson, your question is unclear to me. Do you want to sort by parts of a number? Please edit your question clarifying your doubt and putting what you would like the query to return.

3 answers

4

Yeah, just use the reserved word desc.

Select Coluna From Tabela
Order By Coluna Desc;
  • It doesn’t work, it will order by 58 and 56.

  • Set which parameter you want to return in descending order. " Order By Column Desc;

1

If you have a table that stores 3 dozens in each row, just put the fields in order by, for example:

SELECT d.dezena3, d.dezena2, d.dezena1 FROM dezena d
ORDER BY d.dezena3, d.dezena2, d.dezena1
  • The number is complete 589552 and 568455, only the ordination that has to be separated, but you gave me an idea

1


If you use a SUBSTR taking only the last ten and then the hundreds and then thousands... You could sort each one and join at the end.

SUBSTR(CODIGO, -2,1)
  • I managed to do it anyway, with the reply of @Adriano Gomes, he gave me the idea to do so.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.