Created
May 29, 2013 04:12
-
-
Save keesun/5667933 to your computer and use it in GitHub Desktop.
Board - Post, 1대다 양방향관계에서 최신 게시물의 뷰 카운트가 10 이상인 게시판 조회하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Board> getPopularBoards(){ | |
List<Board> allBoards = boardDao.getAll(); | |
List<Post> recentPosts = new ArrayList()<>; | |
for(Board b : allBoards) { | |
Post p = postDao.getRecentPostFrom(b); | |
recentPosts.add(p); | |
} | |
List<Board> result = new ArrayList()<>; | |
for(Post p : recentPosts) { | |
if(p.getViewCount() > 10) { | |
result.add(p.getBoard()); | |
} | |
} | |
return result; | |
} |
아니야.. 이거보다 더 좋은거.
select b.id from board b
where (select p.count from post p where p.board_id = b.id order by id desc limit 1) > 10
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
이건 N+1 Select라서 쿼리 한방으로 할 수 있는 방법 필요.