首页 > 数据库技术 > 详细

mysql field自定义排序函数

时间:2018-07-03 22:00:21      阅读:257      评论:0      收藏:0      [点我收藏+]
order by field(value,str1,str2,str3..)

参数说明 value为字段名,后面参数为指定要排序的字段值

eg: 按字段degree学历大小排序

select * from education_info where school=‘北京大学‘ order by field(degree,‘博士‘,‘硕士‘,‘学士‘,‘‘) asc 

 

注:如果表中有数据为NULL,并且要将其排到最后可以做如下修改

select * from education_info where school=‘北京大学‘ order by degree is null asc, field(degree,‘博士‘,‘硕士‘,‘学士‘,‘‘) asc 

  

 

mysql field自定义排序函数

原文:https://www.cnblogs.com/watermelon-cmj/p/9260816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!