sql按in中集合排序

1、SELECT * from tbLabelResRelation WHERE lId in(32,18,27,19) order by FIND_IN_SET(lId ,'32,18,27,19');

2、SELECT * from tbLabelResRelation WHERE lId in(32,18,27,19) order by substring_index('32,18,27,19',lId,1);
3、SELECT lCourseId FROM tbNewSchoolCourse35 WHERE lCourseId IN ('2', '7', '4', '10') ORDER BY FIELD(lCourseId, '2', '7', '4', '10')

以上lId是表中列名,'32,18,27,19'这是想要查询的lId的拼接值,注意第二个,后边数字为1时才会按着拼接的字符串排序,注意该方法in中拼接的Id位数要相同

原文地址:https://www.cnblogs.com/qiyongliang/p/3316149.html