@Farrien
Tell me who

Почему такой запрос не выполняется?

SELECT COUNT(t1.id) as howmatcha, COUNT(t2.id) as howmatchb, COUNT(t3.id) as howmatchc, t1.sender_id, t2.sender_id, t3.owner_id, t4.id, t4.nick FROM thread_comments AS t1, forum_posts AS t2, likes AS t3, users AS t4 WHERE t1.sender_id=t4.id, t2.sender_id=t4.id, t3.owner_id=t4.id GROUP BY t4.id ORDER BY howmatcha DESC, t4.nick ASC LIMIT 15

SELECT COUNT(t1.id) as howmatcha, COUNT(t2.id) as howmatchb, COUNT(t3.id) as howmatchc, t1.sender_id, t2.sender_id, t3.owner_id, t4.id, t4.nick FROM thread_comments AS t1, forum_posts AS t2, likes AS t3, users AS t4 WHERE t1.sender_id=t4.id, t2.sender_id=t4.id, t3.owner_id=t4.id GROUP BY t4.id ORDER BY howmatcha DESC, t4.nick ASC LIMIT 15
  • Вопрос задан
  • 93 просмотра
Решения вопроса 1
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
SELECT `u`.`nick`, IFNULL(`tc`.`count`, 0) AS `comments`, 
       IFNULL(`fp`.`count`, 0) AS `posts`, 
       IFNULL(`l`.`count`, 0) AS `likes`
  FROM `users` AS `u`
  LEFT JOIN (
    SELECT `sender_id`, COUNT(*) AS `count` 
      FROM `thread_comments` GROUP BY `sender_id`
  ) AS `tc` ON `tc`.`sender_id` = `u`.`id`
  LEFT JOIN (
    SELECT `sender_id`, COUNT(*) AS `count` 
      FROM `forum_posts` GROUP BY `sender_id`
  ) AS `fp` ON `fp`.`sender_id` = `u`.`id`
  LEFT JOIN (
    SELECT `owner_id`, COUNT(*) AS `count` 
      FROM `likes` GROUP BY `owner_id`
  ) AS `l` ON `l`.`owner_id` = `u`.`id`
  ORDER BY `tc`.`count` DESC, `u`.`nick` ASC
  LIMIT 15
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы