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 に答える