select有条件in要按照in中的数据排序

mybatis中的写法

<select id="selectByIds"     
                resultType="com.hoohui.electronic.util.ExHashMap">
        select
        <include refid="Base_Column_List" />
        from doctor t where t.id in
        <foreach item="item" index="index" collection="array"
                 open="(" separator="," close=")">
        #{item}
        </foreach>
        order by field(id,
        <foreach item="item" index="index" collection="array"
                 open="" separator="," close="">
            #{item}
        </foreach>
        )
    </select>        

mysql语句的写法

SELECT  *  FROM  `doctor`  WHERE  id  IN(580,579,578,577,576,575,574,573,543,305,321,340,388,402,433)  ORDER  BY  INSTR(',580,579,578,577,576,575,574,573,543,305,321,340,388,402,433,',CONCAT(',',id,','))

 

select * from table where id IN (3,6,9,1,2,5,8,7) order by field(id,3,6,9,1,2,5,8,7); 

 

posted @ 2019-05-23 17:48  DHR~小白  阅读(2805)  评论(0编辑  收藏  举报