一:业务场景:查询结果按照批次,库位类型排序
规则:1,批次升序;2,按照'sh','st','rv','of','ld','seq'排序;3,不在这六种类型中,排在后面。
二:sql
select
*
FROM
wms_inv_detail wid where wid.item_id = 112508
ORDER BY wid.batch_no ,
wid.location_type not in ('sh','st','rv','of','ld','seq') asc ,
FIELD(wid.location_type,'sh','st','rv','of','ld','seq') asc ,
wid.loc_code asc ;
三:语法
1)order by in
满足条件返回1,不满足返回0。
所以,满足条件的两行,因为返回值是1,进行ASC排序的时候,就被放置在了最后。
2)FIELD
四:拓展
order by if()