sql - is it possible to order by column based on values, in sqlite? -
suppose table
name status ab 1 cd 4 ef -2 mn 3 pq -1 xy 2
defination of status:
1,2 = success 3,4 = failure -1,-2 = error
expected results after order (order status based on success, failure, error)
ab 1 xy 2 cd 4 mn 3 ef -2 pq -1
while simple order status gives this
ab 1 xy 2 mn 3 cd 4 pq -1 ef -2
is there way sort in expected way, without adding column maps similar status value?
you can use case
statement:
order (case when status in (1, 2) 1 when status in (3, 4) 2 else 3 end)
if have reference table, can join information well.
Comments
Post a Comment