我正在尝试使用正确的语法对多个带有连接的表进行多次计数。
表:
跟随表
id|follower_id|followed_id
相片
id|photoname|userid
这是起点(感谢 ypercube):
SELECT f1.followed_id
, p.*
, COUNT(*) AS followers
FROM follow_table AS f1
JOIN follow_table AS f2
ON f2.followed_id = f1.followed_id
LEFT JOIN (SELECT COUNT(p.*) AS numphotos
FROM `photos` p
GROUP BY p.userid) p2
ON p2.userid = f1.followed_id
WHERE f2.follower_id = $userid
GROUP BY f1.followed_id;
错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 2 行的“COUNT(*) AS Followers FROM follow_table AS f1 JOIN follow_table AS”附近使用正确的语法