이 항목에 문제가 있습니다. 화살표에서 구문 오류가 발생했습니다. 나는 목적에 부질의를 사용하고있다. 나는 '어디에서'와 '있는 것'을 혼합 할 수 있는지 궁금합니다.그룹으로 중첩 된 하위 쿼리
;with books_not_ordered as
(
select BK.book_id
from bkinfo.books BK
where BK.book_id not in
(
select OD.book_id
from bkorders.order_details OD
)
)
select AU.author_id, AU.author_name_last
from bkinfo.authors AU
where exists
(
select BAU.author_id, count(*) as NumBooks
from bkinfo.book_authors BAU
group by BAU.author_id
having count(*) > 1
==>where AU.author_id = BAU.author_id
and
BAU.book_id in
(
select BK.book_id
from bkinfo.books BK
where BK.book_id in
(
select cte.book_id
from books_not_ordered cte
)
)
)
;
go
하지만 BAU.book_id가 그룹화 기준에 없기 때문에 HAVING 오류가 발생합니다. 그러나 Group By에 넣으면 잘못 분류됩니다. –