2013-02-18 2 views
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에 가지고있다. 어쨌든 쿼리에서 중첩 된 쿼리의 값에 액세스하는 것이 더 높습니다.mysql에서 중첩 된 쿼리의 값을 얻는다.

마지막 선택에서 Wall_idWall에 액세스하고 싶습니다. 내가 가장 낮은 쿼리를 선택하고 in 연산자에 의해 사용 된 Wall_idWall을보고 싶습니다.

답변

1

시도 : 만

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; 

마지막 선택

에 Wall_idWall 필요 OR 절 요구 사항에 따라 위치를 변경할 수있는 경우

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; 
관련 문제