mysql数据排序问题

一:业务场景:查询结果按照批次,库位类型排序

规则: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()

https://blog.csdn.net/u013991521/article/details/82634247

猜你喜欢

转载自blog.csdn.net/C18298182575/article/details/84954709