Home > database >  Order by 1, 2, 3, 4, 5 6 how to draw 1 5 4 2 1
Order by 1, 2, 3, 4, 5 6 how to draw 1 5 4 2 1

Time:10-01

post title just for example, the reality is that
We are the newspaper publisher industry, according to the state as a sort of books,

` state ` VARCHAR (10) NULL DEFAULT '0000' COMMENT 'resource state 1 has shelves 2 SanShen refused 3 SanShen through 4 second trial refused to 5 second trial by June first refused to July of first instance by 8 to review

Actually the corresponding code:
Approval of 0000
First by 1000
The first-instance declined to 2000
A second trial with 1100
A second trial declined to 1200
SanShen through 1111
SanShen declined to 1120
Has the shelves 1110

We want to make sorting result is like this in descending order
To review (0000) & gt; Through (1000) of trial & gt; First-instance refused (2000) & gt; The second trial (1100) & gt; A second trial refused (1200) & gt; SanShen through (1111) & gt; SanShen refused (1120) & gt; Has the plane (1100)

This code is order , how do I write the order by statement?

CodePudding user response:

The order by the FIELD (state, 0000100, 0200, 0110, 0120, 0111, 1112, 0111 0).

CodePudding user response:

@ acAndcc



Look at the trouble, thank you.

CodePudding user response:

Look at the trouble, thank you.

CodePudding user response:

It is divided into two results check, check the result of the test=1 set, in the result of the test=0 and sorting, finally to merge the two result sets the union together can

CodePudding user response:

The order by the if (check test=1, null, field (... ))

CodePudding user response:

Point can be in more detail

CodePudding user response:

Trouble new fields, an update to update, 123456, to select again

CodePudding user response:

The order by the field (the state, '2', '4', '0', '1', '3')

CodePudding user response:

I think you can simple point, add a sort field
Sort field so to write
 select Case review status when 0000 then 0 
When 1000 then 1
The else '
End as individual name '


According to this field when I was then Order by sorting, with a Case and the other to go well

CodePudding user response:

Use case, then the order by

Then select *, case when permit_use=2 0 when permit_use=0 then one else 2 end as odbfg from mytable

The order by odbfg