Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL, müssen Zeilen auswählen, die die häufigsten Werte in einer anderen Tabelle enthalten

    SELECT *
      FROM comment
INNER JOIN (SELECT comment.c_id,
                   COUNT(*) AS cnt
              FROM comment
        INNER JOIN logs ON comment.c_id=logs.c_id
             WHERE logs.daterate >= DATE_SUB(CURDATE(), INTERVAL 8 DAY)
               AND logs.rated=1
          GROUP BY comment.c_id) x ON x.c_id = comment.c_id
  ORDER BY x.cnt DESC