gpt4 book ai didi

按照 IN 条件传递的顺序获取 MySQL 记录

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:32 24 4
gpt4 key购买 nike

希望结果与传递给 IN 条件的顺序相同:

SELECT * FROM `table_x` WHERE `id` IN (30, 12, 1001, 24);

获取:

id    | field_a | field_b--------------------------12    | ...     | ...24    | ...     | ...30    | ...     | ...1001  | ...     | ...

期待:

id    | field_a | field_b--------------------------30    | ...     | ...12    | ...     | ...1001  | ...     | ...24    | ...     | ...

最佳答案

SELECT * FROM `table_x` 
WHERE `id` IN (30, 12, 1001, 24)
order by field(id, 30, 12, 1001, 24)

关于按照 IN 条件传递的顺序获取 MySQL 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19704421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com