Home > database >  Mysql to show how to specify the specified sort
Mysql to show how to specify the specified sort

Time:09-18


Id=0 master data, when psupervise_id is not equal to zero equals a id for child data, how to make the note after the data are arranged in the main data, whether can be adjusted by SQL statements. Bosses to solve please, thank!

CodePudding user response:

Resolved
The order by nested if available
 select * from db_supervise order by the if (psupervise_id!=0, psupervise_id, id) 

CodePudding user response:

Upstairs again add a sort field:
 
Select * from db_supervise order by the if (psupervise_id!=0, psupervise_id, id), psupervise_id

CodePudding user response:

Case the when to go, if not too general
  • Related