我有这个表有一些示例数据:
Supplier_ID Product_ID Stock ----------------------------- 1 272 1 1 123 5 1 567 3 1 564 3 2 272 4 2 12 3 2 532 1 3 123 4 3 272 5
我想检查两种产品的供应商:272
和123
结果如下:
Supplier_ID ----------- 1 3
Lukasz Szozd.. 5
你可以使用GROUP BY
和HAVING
:
SELECT Supplier_ID FROM your_tab WHERE Product_ID IN (272, 123) GROUP BY Supplier_ID HAVING COUNT(DISTINCT Product_ID) = 2;
LiveDemo
你可以使用GROUP BY
和HAVING
:
SELECT Supplier_ID FROM your_tab WHERE Product_ID IN (272, 123) GROUP BY Supplier_ID HAVING COUNT(DISTINCT Product_ID) = 2;
LiveDemo