S
S
sys_user2021-11-15 12:20:50
Oracle
sys_user, 2021-11-15 12:20:50

How by means of SQL (oracle) to sort records by the status?

There is such a table
619224aca277c623279977.png
How to sort this table so that first there are products in the "cancelled" status and then all the rest in any order? It only comes to mind to use union (the first query will select records in the "cancelled" status and the second query will select records without records in the "cancelled" status)
Are there any ways to make custom sorting?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BorLaze, 2021-11-15
@sys_user

Orakla is not at hand, but the idea, I think, is clear.

SELECT name, status, price, 
   CASE status WHEN 'cancelled' THEN 0
   ELSE 1 END as pos
FROM TABLE
ORDER BY pos;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question