I have a SQL query which I need to use to order a field. Typically a query would go something like this in hibernate
select * from model order by model.field1, model.field2
The issue is that the first sort needs to be done in a very specific order.
Where the order in field1 has to be filtered in a SPECIFIC order.
So instead of listing cars by an alphabetical order for example. I would prefer to sort in say
Lexus, Ford, Toyota, Mazda, Mercedes etc. Is there a clean way to do this? Currently I get the result and then have to put it in specific lists and is just not very clean. I do not have option of modifying things in the database
Thanks.
You can create a custom ORDER BY using a CASE statement.
The CASE statement checks for your condition and assigns to rows which meet that condition a lower value than that which is assigned to rows which do not meet the condition.
It’s probably easiest to understand given an example: