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:
@ acAndccLook 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 canCodePudding user response:
The order by the if (check test=1, null, field (... ))CodePudding user response:
Point can be in more detailCodePudding user response:
Trouble new fields, an update to update, 123456, to select againCodePudding 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 fieldSort 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 byThen select *, case when permit_use=2 0 when permit_use=0 then one else 2 end as odbfg from mytable
The order by odbfg