在下面的查询中,我尝试按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
然而它似乎并没有起作用。以下是上述查询结果的屏幕截图:
如何通过order
列获取结果?
答案 0 :(得分:1)
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`
答案 1 :(得分:0)
SELECT t1.*, count(t1.*) 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
) AS tmp_table t1
GROUP BY category_uuid
ORDER BY t1.order ASC, t1.created_at DESC