PHP - Mysql订单数据123,如132

时间:2022-10-28 21:50:37

I have a Mysql database like this

我有一个像这样的Mysql数据库

id     name 
1      very big
2      very big
3      big
4      big
5      small
6      small

i wanna order my database like this

我想这样订购我的数据库

id     name 
1      very big
3      big
5      small
6      small
4      big
2      very big

or like this :

或者像这样:

id     name 
2      very big
4      big
6      small
5      small
3      big
1      very big



(indeed sorting from 123456 to 135642 )

how can i do it with php or mysql?

我怎么能用php或mysql做到这一点?

1 个解决方案

#1


1  

You can do:

你可以做:

 order by id % 2,
          (case when id % 2 = 0 then id end) asc
          id desc;

#1


1  

You can do:

你可以做:

 order by id % 2,
          (case when id % 2 = 0 then id end) asc
          id desc;