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); 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM