sql >> データベース >  >> RDS >> Mysql

グループ化時の問題

    これを試してみてください(機能するかどうか教えてください):

    SELECT forum_categories.title, forum_messages.author, 
       forum_messages.date AS last_message
    FROM forum_categories
    JOIN forum_topics ON forum_topics.category_id=forum_categories.id
    JOIN forum_messages ON forum_messages.topic_id=forum_topics.id
    JOIN (SELECT MAX(m.date) as date, top.category_id  
         FROM forum_messages m
         JOIN forum_topics top ON m.topic_id = top.id
         GROUP BY top.category_id) as t
      ON t.category_id = forum_topics.category_id AND t.date = forum_messages.date
    WHERE forum_categories.id=6
    GROUP BY forum_categories.id
    

    2番目のオプションは次のとおりです。

    SELECT forum_categories.title, forum_messages.author, 
           forum_messages.date AS last_message
    FROM forum_categories
    JOIN forum_topics ON forum_topics.category_id=forum_categories.id
    JOIN forum_messages ON forum_messages.topic_id=forum_topics.id
    WHERE forum_categories.id=6
    AND forum_messages.date = (SELECT MAX(date)
                               FROM forum_messages t
                               WHERE t.topic_id = forum_topics.id)
    GROUP BY forum_categories.id
    ORDER BY forum_categories.date ASC
    


    1. LISTAGGを使用できません

    2. MySQLは、複数の値を使用してAGAINSTに一致します

    3. AFTER LOGON(Oracle)は、拡張子が付けられたPostgreSQLでトリガーされます– login_hook

    4. OracleDatabaseでサポートされている言語のリスト