我有这个MySql查询:
SELECT * FROM `tbl_prods`
WHERE `id` IN ('58', '169', '166', '496', '24', '28')
ORDER BY FIND_IN_SET(`id`, '58, 169, 166, 496, 24, 28')
结果很奇怪:
24
28
166
169
496
58
我无法弄清楚如何通过FIND_IN_SET
我做错了什么想法?
答案 0 :(得分:2)
中不应有空格
'58, 169, 166, 496, 24, 28'
将其更改为
'58,169,166,496,24,28'
答案 1 :(得分:1)
使用FIELD
代替FIND_IN_SET
:
SELECT * FROM `tbl_prods`
WHERE `id` IN ('58', '169', '166', '496', '24', '28')
ORDER BY FIELD(`id`, '58', '169', '166', '496', '24', '28')