sql按照in中的顺序进行排序 mysql
经测试以下三种情况,都可以。
SELECT a.id,a.name as goods_name,a.logoimg,b.name as store_name FROM sh_goods a LEFT JOIN sh_store b on a.store_id = b.id WHERE ( a.id IN ('1127','1124','1128','1130','1132','1134') ) order by find_in_set(a.id,'1127,1124,1128,1130,1132,1134');
SELECT a.id,a.name as goods_name,a.logoimg,b.name as store_name FROM sh_goods a LEFT JOIN sh_store b on a.store_id = b.id WHERE ( a.id IN ('1127','1124','1128','1130','1132','1134') ) order by field(a.id,1127,1124,1128,1130,1132,1134);
SELECT a.id,a.name as goods_name,a.logoimg,b.name as store_name FROM sh_goods a LEFT JOIN sh_store b on a.store_id = b.id WHERE ( a.id IN ('1127','1124','1128','1130','1132','1134') ) order by substring_index('1127,1124,1128,1130,1132,1134',a.id,1);