且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查找列表/集合是否包含在另一个列表中

更新时间:2023-11-29 08:33:52

你已经很近了

SELECT order_id
FROM orders
WHERE product_id in (222,555) 
GROUP BY order_id
HAVING COUNT(DISTINCT product_id) = 2

关于您在关系代数中的出于好奇"问题,这可以通过 .AFAIK 没有 RDBMS 实现了任何扩展,使其在 SQL 中变得如此简单.

Regarding your "out of curiosity" question in relational algebra this is achieved simply with division. AFAIK no RDBMS has implemented any extension that makes this as simple in SQL.