mysql中的排序

单字段排序

select name, hex(name) from a order by name desc;

实际以字节码进行排序,第一个字相同时则比较第二个字的字节码。单字段排序时,其他字段按照自然排序。

多字段排序

select * from a order by code, name desc;

MySQL先以code做降序排序,在该基础上再使用name降序排序。

另外还可以使用contat函数把多个字段拼接进行排序。但要保证字段不为null。

select * from a order by concat(code,name) desc;

分页排序

select * from persons 
order by lastname limit 0,10;

猜你喜欢

转载自blog.csdn.net/weixin_40632321/article/details/83579257