gpt4 book ai didi

Mysql 按其他表的数据排序

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

我有表“orderby

+-----------------+
| id | data |
+-----------------+
| 1 | 4,2,5,6 |
+-----------------+

和第二个表数据

+-----------+
| id | ... |
+-----------+
| 2 | ... |
+-----------+
| 4 | ... |
+-----------+
| 5 | ... |
+-----------+
| 6 | ... |
+-----------+

我想按orderby表数据列对数据表进行排序。

像这样:

+-----------+
| id | ... |
+-----------+
| 4 | ... |
+-----------+
| 2 | ... |
+-----------+
| 5 | ... |
+-----------+
| 6 | ... |
+-----------+

我尝试了这个查询:select * from data order by field(id,(select group_concat(data) from orderby))

但不起作用。

最佳答案

最好的解决方案是将列 orderby INT UNSIGNED 添加到您的 data 表中,并使用数字来获取正确的顺序。

如果您需要排序取决于用户,则必须使用包含用户 ID、数据 ID(来自您的 data 表)和 orderby 值的单独表。

您在代码中使用的单个 orderby 值将不起作用。 (也许有可能,但我认为实现起来会很困难,而且效果也不会很好。)

关于Mysql 按其他表的数据排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36560463/

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