0

如何优化此查询?如果您需要表格结构,请告诉我,但这是作为 Vanilla 论坛的自定义插件完成的

SELECT
    G.*
FROM
    (
        SELECT
            D.DiscussionID,
            A. NAME AS Category,
            D. NAME,
            U. NAME AS USER,
            D.CountComments,
            IFNULL(
                MAX(C.DateInserted),
                D.DateInserted
            ) AS Updated
        FROM
            GDN_Discussion AS D
        LEFT OUTER JOIN GDN_Comment AS C ON D.DiscussionID = C.DiscussionID
        INNER JOIN GDN_Category AS A ON A.CategoryID = D.CategoryID
        LEFT OUTER JOIN GDN_User AS U ON U.UserID = D.InsertUserID
        WHERE
            A.CategoryID = '626'
        GROUP BY
            D.DiscussionID
    ) AS G
ORDER BY
    G.Updated DESC
LIMIT 0, 10
4

0 回答 0