我有一张包含以下数据的表格。
Name Product
Ram Acer
Indu Sony
Indu Acer
Rahul Sony
Divya Acer
Divya Dell
现在我想查询选择同时包含Acer和Sony产品的名称。
结果应该是Indu
。
答案 0 :(得分:2)
select Name
from your_table
where Product in ('Acer', 'Sony')
group by Name
having count(Product) > 1
如果您要同时寻找更多产品,那么您必须增加计数中的数量:
where Product in ('Acer', 'Sony', 'Dell')
...
having count(Product) > 2
答案 1 :(得分:0)
这将选择ACER
和SONY
SELECT DISTINCT Name
FROM tableName
WHERE Product = 'Acer' AND
Name IN (SELECT Name
FROM tableName
WHERE Product = 'Sony')