| Publisher | Book |
| ------------------------|
| A | Pride and Prejudice |
| B | 1984 |
| B | The Great Gatsby |
| B | Pride and Prejudice |
| C | 1984 |
| C | The Great Gatsby |
| D | Beloved |
| D | 1984 |
| D | The Great Gatsby |
| E | Beloved |
| E | 1984 |
| E | The Great Gatsby |
| E | Sense and Sensibility |
| Orders |
| ---------------- |
| Beloved |
| The Great Gatsby |
| 1984 |
现在,我想查找在订单列表中发布所有图书的所有发布商。
即D and E
答案 0 :(得分:1)
您必须使用RIGHT JOIN,因为只需要显示在订单表中提及图书的发布商。
SELECT a.publisher
FROM publishersupply a RIGHT JOIN orders b
ON a.book=b.book
WHERE a.publisher IN ('D','E')
GROUP BY a.publisher,a.book,b.book;
答案 1 :(得分:0)
以下是一种使用join
,group by
和having
的方法:
select p.publisher
from publisher p join
orders o
on p.book = o.book
group by p.publisher
having count(*) = (select count(*) from orders o);