0
How do I make a order by
by text criterion?
I have a column with some ratings and wanted it to come in the order I determine.
Example:
'carro1'
'carro3'
'carro5'
'carro10'
'carro2'
0
How do I make a order by
by text criterion?
I have a column with some ratings and wanted it to come in the order I determine.
Example:
'carro1'
'carro3'
'carro5'
'carro10'
'carro2'
3
You could create a ranking column.
From what I understand there are few records, so creating a classification column, you could give a numbering for each of the record of your listing, so in the future if any in the category appears, just edit in the bank, or even make an administrative menu for such a purpose.
SELECT
carName
FROM
exemple
ORDER BY
CASE carName
WHEN 'carro1' THEN 0
WHEN 'carro3' THEN 1
WHEN 'carro5' THEN 2
WHEN 'carro10' THEN 3
WHEN 'carro2' THEN 4
ELSE 999
END
Testable example: http://sqlfiddle.com/#! 18/49da0/11
David, thank you, it worked. Abs.
Browser other questions tagged sql sql-server
You are not signed in. Login or sign up in order to post.
Maikol, the idea has not yet become clear.. could expose more details?
– Cleber Griff
and what would be the order you determine ?
– Marco Souza
Oops. I have a column with some ratings and wanted to display the query result with the ratings in the order I determine.
– Maikol Oliveira
Possible duplicate of How to select with ORDER BY and different criteria?
– Marconi
For your specific case, just take substring and cast to int, that car 10 will come at the end. But the real problem is not that, probably. This is known as XY Problem, which is when you ask about the solution you think will solve, rather than exposing the real problem.
– Bacco
I think the same problem is how to store the data... "display the result in the order I determine" if it is to determine the order of each item, better create a column and sort by it
– Rovann Linhalis
Rovann, I did that and it was the solution. thanks, abs.
– Maikol Oliveira