I have a table as below

i need to create a query to display the below

CodePudding user response:
following, Need to make this sort. to return data sorted by status with limit on every one
CodePudding user response:
As you didn't explain rules which lead from A to B, I guess we're free to make our own ones.
Using case
expression in order by
clause might be one option:
SQL> select id, type
2 from test
3 order by case when id = 1 then 1
4 when id = 2 then 2
5 when id = 5 then 3
6 when id = 3 then 4
7 when id = 4 then 5
8 when id = 6 then 6
9 end;
ID TYPE
---------- ----------
1 1
2 1
5 0
3 1
4 1
6 0
6 rows selected.
SQL>