sql >> Base de Datos >  >> RDS >> Mysql

MySQL, necesita seleccionar filas que tengan los valores más frecuentes en otra tabla

    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