我将如何使用 Exists 查询为拥有不止一本书但没有图书销售的作者显示作者信息?我以为这是解决方案,但我又不确定。据我所知,没有一个作家没有卖过任何书。我没有收到错误。只是一个空集。对我来说已经晚了,所以也许我错过了一些东西:
SELECT author_id
, author_name_last
, author_name_first
FROM a_bkinfo.authors
WHERE EXISTS (
SELECT 1
FROM a_bkinfo.book_authors BS
JOIN a_bkorders.order_details OD on BS.book_id = OD.book_id
WHERE quantity > 1
)
AND NOT EXISTS (
SELECT MAX(orders)
FROM (
SELECT book_id
, count(order_id) AS orders
FROM a_bkorders.order_details
GROUP BY book_id
HAVING count(order_id) = 1
) t
)
;