0
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。

4

2 回答 2

1

尝试:

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;
于 2013-02-18T11:12:52.470 回答
0

如果您在最后一次选择中只需要 Wall_idWall,请尝试此操作

SELECT *, count(idWallHasWallPost) as republish,(select Wall_idWall from follower where User_idUser=1) as Wall_idWall 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;

或者您可以根据您的要求更改 where 子句。

于 2013-02-18T11:20:41.843 回答