SELECT *, count(idWallHasWallPost) as republish FROM admin_pw.wall_has_wallpost
    where WallPost_idWallPost in
    (select WallPost_idWallPost from wall_has_wallpost where Wall_idWall in
    (select Wall_idWall from follower where User_idUser=1))
    group by WallPost_idWallPost
    having republish>1;


我在mysql中有此嵌套查询。无论如何,是否有权限从查询中较高的嵌套查询中获取值。

我想在最后一次选择中访问Wall_idWall。我选择查询最低的查询,并希望查看in运算符使用了哪个Wall_idWall。

最佳答案

尝试:

SELECT w.*, count(w.idWallHasWallPost) as republish, v.all_Wall_idWall
FROM admin_pw.wall_has_wallpost w
join (select h.WallPost_idWallPost,
             group_concat(distinct h.Wall_idWall) all_Wall_idWall
      from wall_has_wallpost h
      join follower f on h.Wall_idWall = f.Wall_idWall and f.User_idUser=1
      group by h.WallPost_idWallPost) v
on w.WallPost_idWallPost = v.WallPost_idWallPost
group by WallPost_idWallPost
having republish>1;

关于mysql - 获取MySQL中嵌套查询的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14934672/

10-16 19:46
查看更多