mysql数据库limit分页,排序操作

看到网上很多朋友在问,limit分页之后按照字段属性排序的问题,在这里分享一下我的用法:

  1.网上答案:    

    每页显示5个,显示第三页信息,按照年龄从小到大排序
    select * from student order by age asc limit 10,5;

    

    

    这个答案是先实现了排序,再分页的操作,而很多人想要的并不是这样的效果,因为这样就跟原表数据排序完全不一样了,其实想要得到先分页再排序的结果很简单。

  2.我的用法:

    很简单,只需要在查询操作外面加个小括号提升优先级即可;

    (select * from student limit 10,5)order by age asc ;

    

    

猜你喜欢

转载自www.cnblogs.com/pyyolo/p/11228001.html