场景:
查出当前用户的关注的人列表,在查询出关注的人创作的作品数量;
SQL语句如下:
select a.uc_id,a.collection_id,a.state,b.avatar,b.name,b.user_id,COUNT(1) as sum from user_collect as a INNER JOIN user as b on b.user_id = a.collection_id INNER JOIN byline as c on c.user_id=b.user_id where a.type=4 and a.user_id=87 and a.state!=1 group by(a.collection_id) limit 0,10;
例如:
关注表:
用户表:
作品表:
想要的结果:
SQL语句:
select a.id,b.name,b.user_id,count(1) from A as a inner join user as b on b.id=a.user_id inner join p as c on c.user_id=a.user_id where a.from_user=1 group by (a.userid);