我正在尝试使用连接来对多个表进行多次计数。
表:
follow_table
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服务器版本对应的手册,以便在'COUNT(*)AS跟随者附近使用正确的语法FROM follow_table AS f1 JOIN follow_table AS'在第2行