Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL, è necessario selezionare le righe con i valori più frequenti in un'altra tabella

    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