我有以下表格:Table1
和Table2
。我想要的输出是seller_name
和id_seller
,其中id_seller
仅具有不同的product
表1:
+-----------+---------+
| id_seller | product |
+-----------+---------+
| 01 | 10 |
| 01 | 10 |
| 01 | 12 |
| 02 | 12 |
| 02 | 14 |
| 03 | 17 |
| 03 | 17 |
| 04 | 8 |
+-----------+---------+
表2:
+-----------+-------------+
| id_seller | seller_name |
+-----------+-------------+
| 01 | luigi |
| 02 | mario |
| 03 | bill |
| 04 | simon |
+-----------+-------------+
输出示例:
+-----------+-------------+
| id_seller | seller_name |
+-----------+-------------+
| 02 | mario |
| 04 | simon |
+-----------+-------------+
答案 0 :(得分:0)
select t2.id_seller, t2.seller_name
from table2 t2
join table1 t1 on t1.id_seller = t2.id_seller
group by t2.id_seller, t2.seller_name
having count(t1.product) = count(distinct t1.product)
答案 1 :(得分:0)
您可以在下面尝试
select table1.id_seller, seller_name
from table1 left join table2 on table1.id_seller=table2.id_seller
group by table1.id_seller, seller_name
having count(product)=count(distinct product)