gpt4 book ai didi

sql - 搜索结果按特定顺序显示?

转载 作者:行者123 更新时间:2023-11-29 05:44:25 26 4
gpt4 key购买 nike

SELECT id FROM films WHERE id IN (90,4,40)

结果

4
40
90

但我希望它返回 90,4,40我应该做什么? (mysql)


抱歉,还有一个问题:

SELECT id FROM films WHERE id IN (90,4,40) ORDER BY FIELD(id, 90, 4, 40) 可以但说实话

 for ( $i = 1; $i <10; $id ++ ){
$IDarray[] = random();
}


SELECT id FROM films WHERE id IN "(". implode(',',$IDarray). " ) ";

我想按上面的 ID 排序,但 ID 是随机的,我想保持 ID 的随机顺序

最佳答案

ORDER BY CASE `id` WHEN 90 THEN 0
WHEN 4 THEN 1
WHEN 40 THEN 2
ELSE 3
END CASE

ORDER BY FIND_IN_SET(`id`, '90,4,40')

ORDER BY FIELD(`id`, 90, 4, 40)

关于sql - 搜索结果按特定顺序显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3748688/

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