Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

MySQL, precisa selecionar linhas que tenham os valores mais frequentes em outra tabela

    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