Skip to content

Instantly share code, notes, and snippets.

@keesun
Created May 29, 2013 04:12
Show Gist options
  • Save keesun/5667933 to your computer and use it in GitHub Desktop.
Save keesun/5667933 to your computer and use it in GitHub Desktop.
Board - Post, 1대다 양방향관계에서 최신 게시물의 뷰 카운트가 10 이상인 게시판 조회하기
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;
}
@keesun
Copy link
Author

keesun commented May 30, 2013

아니야.. 이거보다 더 좋은거.

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