目录

hymn

忽有故人心头过,回首山河已是秋。

MySQL 排序 FIELD

需求:按照指定字符串排序,

分析:运用 FIRLD 可以实现

问题:字段中有null 值,需要放到最后

// 在排序前加 rating is null 并且 在 FLELD 中加 IFNULL(rating,"")
SELECT * 
FROM `dl_school`
ORDER BY rating is null,FIELD(rating,"A+","A","A-",IFNULL(rating,"")),sort DESC

标题:MySQL 排序 FIELD
作者:hymn
地址:https://dxyhymn.com/articles/2020/10/30/1604051422187.html