order by specific text [closed]

0

How do I order by by text criteria?

I have a column with some classifications and I wanted it to come in the order I determine.

Example:

'carro1'
'carro3'
'carro5'
'carro10'
'carro2'
    
asked by anonymous 12.06.2018 / 21:08

1 answer

3

You could create a sort column.

From what I understand are a few records, so by creating a sort column, you could give a numbering for each of the records in your listing, so if in the future some category appears, just edit in the database, or even do an administrative menu for this purpose.

But if you still want to filter specifically for the records cited, here is an example of a "Temporary Palliative Emergency Solution," commonly called gambiarra.
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: link

    
12.06.2018 / 21:40