SubQuery로 총 회차, 총 조회수, 총 추천수 가져오기

2021. 12. 21. 17:34
반응형

select * from
(select book_idx, book_title, book_writer, book_intro, book_genre, book_subgenre, book_regDate, book_recentDate, book_uploadPath, book_fileName, book_uuid, 
(select count(*) from book_detail where book_bd_idx = a.book_idx) chapterCount,
(select sum(bd_count) from book_detail where book_bd_idx = a.book_idx) bookReadCount,
(select count(*) from book_recommend where book_br_idx = a.book_idx) bookRecommendCount
from book a
order by a.book_idx desc) as T1
limit #{skip}, #{amount};

 

서브쿼리문이 이렇게도 작성이 되는구나

이렇게 쓰면 해당 서브쿼리 컬럼명에 해당하는 getter setter를 VO에 만들어주면 알아서 값을 받아옵니다 후후

 

※ 지인의 도움을 받았읍니다

group by 와 having을 써야하는 줄 알고 고민이었는데 쓸 필요가 없어서 where 조건으로 해결!

반응형

BELATED ARTICLES

more