gpt4 book ai didi

mysql - 为什么我的 MySQL 查询排序不正确?

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

在下面的查询中,我尝试按 fc.order 按升序对结果进行排序:

SELECT *, count(*) AS threads_count FROM (
SELECT fc.uuid AS category_uuid, fc.name, fc.description, fc.order, fc.icon,
u.uuid AS user_uuid, u.username, u.avatar
FROM forum_categories AS fc
INNER JOIN forum_threads AS ft ON fc.id = ft.forum_category_id
INNER JOIN users as u ON ft.created_by = u.id
ORDER BY fc.order ASC, ft.created_at DESC
) AS tmp_table GROUP BY category_uuid

但是它似乎不起作用。以下是上述查询结果的屏幕截图:

enter image description here

如何获取按 order 列排序的结果?

最佳答案

好的,谢谢大家,但我明白了:

SELECT * FROM (
SELECT *, count(*) AS threads_count FROM (
SELECT fc.uuid AS category_uuid, fc.name, fc.description, fc.order, fc.icon,
u.uuid AS user_uuid, u.username, u.avatar
FROM forum_categories AS fc
INNER JOIN forum_threads AS ft ON fc.id = ft.forum_category_id
INNER JOIN users as u ON ft.created_by = u.id
ORDER BY ft.created_at DESC
) AS t1 GROUP BY category_uuid
) as t2 ORDER BY `order`

关于mysql - 为什么我的 MySQL 查询排序不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38025178/

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