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 조건으로 해결!
반응형
'※ 유용한 스크랩' 카테고리의 다른 글
Bootstrap으로 모달창 띄울 때 (0) | 2022.03.05 |
---|---|
코드를 정렬해주는 사이트 (0) | 2022.02.04 |
로컬호스트를 남에게 보여주고 싶을 때. Ngrok (0) | 2021.12.20 |
PaaS 서비스 비교 정리 (0) | 2021.11.22 |
CK editor5 내용을 전송하는 법 (0) | 2021.11.10 |