mysqlはwhere in()の順序でソートされ、find_in_set()関数

2266 ワード

select * from table where id in ('783',' 769',' 814',' 1577',' 1769')
order by find_in_set( id, '783, 769, 814, 1577, 1769' )

検出:769 1577 814 1769 783
なぜ783 769 814 1577 1769の順番ではないのですか?
注意:find_に原因が検出されましたin_setの中、もし
find_in_setの2番目のパラメータにスペースがあると、mysqlクエリの前にtrimスペース文字が与えられないため、順序が乱れます.
so...
スペースを削除した後:
select * from table where id in ('783',' 769',' 814',' 1577',' 1769')
order by find_in_set( id, '783,769,814,1577,1769' )

注意はただ取り除いただけだ '783,769,814,1577,1769'
 

検出:
783 769 814
1577 1769
これでwhere in+find_in_setのソート、find_in_setは ソートも ですよ.

edit by @hxl5u