1. 程式人生 > >MySQL中函式field()的用法

MySQL中函式field()的用法

MySQL中的field()函式,可以用來對SQL中查詢結果集進行指定順序排序。

str與str1,str2,str3,str4比較,其中str指的是欄位名字

意為:欄位str按照字串str1,str2,str3,str4的順序返回查詢到的結果集。如果表中str欄位值不存在於str1,str2,str3,str4中的記錄,放在結果集最前面返回。

<select id="selectMapByBizIds" resultType="java.util.Map">
        select mch.name,mch.bizMchId appId,mch.mch_logo,mch.redirect_url,mch.type,mch.require_user_auth,bmap.mchId merchantId
        from agency_biz_mch mch inner join agency_merchant_map_bizmch bmap on mch.bizMchId=bmap.bizMchId
        where mch.status=1 and  mch.bizMchId in (${bizIds})
        order by field (mch.bizMchId,${bizIds})
  </select>