gpt4 book ai didi

php - MySQL PHP - 根据不同位置选择 WHERE

转载 作者:行者123 更新时间:2023-11-29 13:07:41 25 4
gpt4 key购买 nike

是否可以根据特定 ID 上设置的订单值对数据进行排序?

我想做以下事情:

    ID - Position
1 - 3rd
2 - 4th
3 - 5th
4 - 6th
10 - 7th
11 - 8th
12 - 9th
13 - 10th
14 - 11th
83 - 2nd
84 - 1st

我一直在尝试实现这个,但它没有生成正确的顺序:

SELECT * FROM table_name WHERE id IN (1,2,3,4,5,6,7,81,82) ORDER BY id = 3 DESC, id = 4 DESC, id = 5 DESC, id = 6 DESC, id = 7 DESC, id = 8 DESC, id = 9 DESC, id = 1 DESC, id = 2 DESC

如果我不清楚,请向我询问更多信息。预先感谢您。

最佳答案

SELECT * FROM table_name WHERE id IN (1,2,3,4,5,6,7,81,82) ORDER BY CAST(SUBSTR(position, 1, CHAR_LENGTH(position) - 2) as unsigned)

关于php - MySQL PHP - 根据不同位置选择 WHERE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22496100/

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